Tutorial |
Top Installation Introduction Samples Tutorial Reference Release Notes
Cell values can be used in both queries and rules. This allows variable inputs from the user both in the reasoning and query processes.
The query used in the example so far contained the input value for Quantity
.
It would be better if the query picked up the quantity value from another cell.
That is done by adding place markers of the form _N
in the query.
The place markers are then replaced with optional cell arguments to RQuery().
To get the Quantity
from cell A7 in our example, the query would
be:
=RQuery(PriceRules, "Find UnitPrice when Quantity = _1", C7)
To do this:
RQuery()
in A6.=RQuery(PriceRules, "Find UnitPrice when Quantity = _1", C7)
Because C7 is a parameter in the query, the query becomes dependent on C7,
so whenever the quantity in C7 changes, the query is recalculated. You can have
any number of place holders, numbered sequentially (_1, _2, _3...), with corresponding
cell arguments as parameters to RQuery()
.
The spreadsheet should look like this:
Just as rule queries can be dependent on other cells, the rules themselves can be as well.
In the example so far, the discount quantity of 20 is stored directly in the rules. It would be more flexible if that value was stored in a cell and the rules picked up the value from the cell.
A function, RCell()
allows you to do that. It takes a cell value
and assigns it to an ARulesXL fact.
RCell(Fact, Cell)
Here's how to use RCell()
:
UnitPrice = 10 when Quantity < DiscountQuantity
UnitPrice = 8 when Quantity >= DiscountQuantity
=RCell("DiscountQuantity", B1)
The spreadsheet now looks like this:
Turning on dependency arrows (blue in the screen shot) in Excel (using Tools | Formula Auditing), you can see how the query in D7 depends on C7 and the range PriceRules, and that PriceRules depends on D1.
Experiment with different values in C7 and D1 to see how the rules and spreadsheet work together.
Cells should be linked to rules when the rules themselves depend on the cell, as in the case of discount quantity.
Cells should be linked to queries when the cell contains data for a specific case to be analyzed, such as the quantity ordered.
Open in New Window to Print |
---|
Copyright ©2005-7 Amzi! inc. All Rights Reserved.
|