Array Variables (available at all variable levels) are a way to have a single variable execute a different formula for each value in an array. Any variable that references an array variable also becomes an array variable, allowing for large chains of calculations that primarily use the same variable code differing only where necessary.
1. Create an Array
Arrays are the foundation of array variables and are configured on each model. See the Arrays section for more details on how to set up and configure arrays.
2. Set up an Array Variable
Once an array is configured, create an array variable by simply setting the Array field on any existing variable (or create a new variable with the Array field set). Upon saving the variable properties, the formula builder below will update to show a formula per array value. Users can start with a single formula, if needed, and then alter the formula for each array value, if appropriate.
3. Referencing an Array Variable
Referencing an array variable from another variable is easy. Simply select the variable in the formula builder just like referencing any other variable. By referencing an array variable, the current variable also becomes an array variable, iterating for each value in the array. It is not necessary, however, to specify the array in the variable properties, unless different formulas are needed for each array value. This simplifies the development, allowing a single formula to be executed for each array value.
An array variable reference in the formula builder
Each array variable will be clearly marked with the array icon () in the list view on variable details and within the relationship view, so it is easy to see the array dependency chain that has been created.
4. Array Aggregation
Array variable results can also be aggregated when referenced, allowing various aggregation options such as sum, average, and median to be applied to the results of all array value results. It is also possible to reference the results of a single array value result. If aggregated, the variable referencing the aggregated results will no longer be an array variable, since the result is converted into a single value.
Single Value array aggregation of an array element.
NOTE: When using array aggregation on a product or portfolio aggregate, the aggregate is performed first for each array value, and then the results for each array value are aggregated. This is an important order of operations to consider during development.
Corporate array aggregation of portfolio aggregate array variable
5. Viewing Array Variable Results
During calculation, SLOPE will automatically determine array dependencies and iterate the array values, calculating each variable for each value in the array, and using the unique formula values for each array value where necessary. The array value used for each variable result is written to the database so that reporting users can filter, sort, or otherwise slice the data with these values.
Example reporting output for array variables.
NOTE: Variables can only depend on a single array. Referencing variables that depend on multiple arrays within a single calculation chain will cause a validation error.