Expression Dimensions as Virtual cBase Columns
Besides acting like dimensions, expression dimensions also act as if they are backed by actual cBase columns. Just like cBase columns, expression dimensions have calcs automatically generated for them, and the value() function can be used on them.
When Spectre opens a cBase, it automatically generates calcs for each column in the cBase. For instance, if there is a Salesperson column in the cBase, then a Salesperson calc is generated with the expression `info(value("Salesperson"))`). The same is true for expression dimensions: declaring an expression dimension automatically generates a calc with the same name using the info() function. For calcs that are generated from cBase columns, you can control the summary function used for the generated calcs with the summary-type attribute on the column and add tags in a Build script. However, there is no corresponding summary-type attribute for expression dimensions; they always use info.
For example, define an expression dimension like this:
cplan {
cplan-input "inventory.cplan"
dimension "Warehouse Code" `substr(value("Location Code"),1,3)`
}
Then, you can use the dimension in a window summary column without needing to explicitly define a calc:
window {
dimension "Item ID"
column "Warehouse Code"
...
}
The value() function, when invoked in a cBase-row context, fetches the value at a particular row from the underlying cBase. The function works for expression dimensions the same way it works for cBase columns. If the argument to value() matches an expression dimension, then it behaves just like the expression used in that dimension. For example, with the Warehouse Code dimension previously defined, you can filter a cPlan to a specific set of warehouse codes like this:
cplan {
...
filter `is_in(value("Warehouse Code"), "WHA", "WHB")`
}