What is an Expression Dimension?

At dive time, an expression dimension generates a new dimension based on a calculation that uses other columns. The expression must be specified in a cPlan and associated with a new dimension name. When a Dive file runs referring to the cPlan, the expression dimension is automatically calculated and becomes a divable dimension.

For example, you can add a dimension called "Order Month" to a cPlan:

cplan {

input "sales.cbase"

dimension "Order Month" `period("gregorian month", value("Order Date"))`

}

Then, you can use the new dimension in a dive:

window {

dimension "Order Month"

...

}

Note that the dimension tag can be used in two ways in a cPlan.

  • When associated with an existing dimension—add named groups, change the label, or change the format
  • When associated with an expression and a new dimension name—create new data columns at run time

Attributes

There are two attributes that you can set on a dimension when you create an expression dimension: suggested-dimension and sort-by. These attributes match the attributes of the same names on the column and add tags in a Build file.

  • suggested-dimension can be set to false to tell clients like ProDiver that the new dimension should not appear in the Console, although it can still be promoted to a dimension and then dived on—this makes it roughly equivalent to the classic model concept of a dynamic dimension. The default value of suggested-dimension is true.
  • sort-by can change the sort order for expression dimensions of type string. Unlike in the build case, you can provide an expression for sort-by. For example, if you want a Month Name dimension, but want it sorted by month number instead of alphabetically:
  • dimension "Month Name" `month_name(value("Date"))` sort-by=`month(value("Date"))`

Deriving dimensions

In addition to date roll-up expressions like the previous Order Month example, expression dimensions can generate derived dimensions. For example:

dimension "Owner/Operator" `coalesce(value("Owner"),value("Operator"))`

Partitioning dimension values

Expression dimensions can partition dimension values. For example to build a histogram:

dimension "Age Group" ```

case(value("Age") <= 10, "0 to 10",

value("Age") <= 20, "11 to 20",

value("Age") <= 30, "21 to 30",

"31+")

```

Using expression dimensions in QuickViews

Note that in addition to dive windows, you also can use expression dimensions in QuickViews. For example:

quickview-set {

cplan "population.cplan"

dimension-quickview "Age Group"

}

See also: