Cumulative Columns
Spectre cumulative expressions can be used in other calculations. When a cumulative column is used in another calculation, that calculation accesses the cumulative number on each row. For example:
dive { cplan "/cplans/basic.cplan" { calc "Cumulative Weight" ``` calc("Weight") + previous(calc("Cumulative Weight"), 0)``` } window { dimension "Color" column "Weight" column "Cumulative Weight" column "Total Remaining" ``` top(calc("Weight")) - calc("Cumulative Weight")``` } }
The results:
The Cumulative Weight value on each row is the sum of the current row's Weight value plus the Cumulative Weight value from the previous row. The example uses zero as the initial value because there is no previous row.
The Total Remaining calculation uses the totals row of the Weight column (top() function) and subtracts the Cumulative Weight for the row. The following variation returns the same result.
add "Total Remaining" `top(calc("Weight")) - value("Cumulative Weight")`
Cumulative column functionality is also available in ProDiver calculations against a cBase. Note that unlike the limitation on classic Models, Spectre cumulative calculations can be referenced by other ProDiver calculations. To use, open a cBase in ProDiver, add a new total column, and select the Cumulative checkbox in the Options tab.
If you are a ProDiver user, see also: Using Cumulative Columns to Rank Values.