Calc Sets

Calc-sets are groupings of calculations defined in a cPlan. A dive file can add several columns at once by specifying a calc-set. For example, if a calc-set "Units Calcs" was defined with 10 unit-related calculations, then the following window would have 11 columns (one for the dimension, and one for each calculation in the calc-set):

 window {
    dimension "Sales Region"
    calc-set "Units Calcs"
  } 

You can declare the calc-set all at once, listing each calculation that should go in it. For example:

  calc "Red Units" `calc("Units")` filter=`value("Color") = "Red"` 
  calc "Green Units" `calc("Units")` filter=`value("Color") = "Green"` 
  calc "Blue Units" `calc("Units")` filter=`value("Color") = "Blue"` 
  
  calc-set "Color Units" {
    calc "Red Units"
    calc "Blue Units"
    calc "Green Units"
  }

This allows you to declare the calculations in a different order than they appear in the calc-set, which might be important if the calculations make references to one another.

Alternatively, you can include a for-loop and a parameter when defining the calc-set. For example:

for "Color" "Red" "Green" "Blue" {
  calc "$(Color) Units" `calc("Units")` filter=`value("Color") = param("Color")`
  calc-set "Color Units"
}

This Color Units calc-set could be included in a time series definition. ClosedFor example, here the calc-set is part of a summary block:

time-series {
  date "Order Date"
  summary "Units" { 
    calc-set "Color Units"
  } 
  ranges {
    year-to-date
    month-to-date 
  } 
}

A calc-set tag can also be part of a time series block. For example, here the placement of the calc-set tag makes all the columns generated for the time series part of the defined calc-set.

cplan {

input "Widgets.cbase"

calc "A1 Units" `calc("Units")` filter=`value("Product") = "Widget A1"`

calc "A2 Units" `calc("Units")` filter=`value("Product") = "Widget A2"`

calc "A3 Units" `calc("Units")` filter=`value("Product") = "Widget A3"`

time-series "Big Orders" {

date "Order Date"

anchor `date("2004/06/04")`

filter `value("Units") > 20`

summary "A1 Units"

summary "A2 Units"

summary "A3 Units"

ranges {

year-to-date

}

calc-set "Big Orders"

}

}

See also: Calculations: Build versus cPlan