Skip to main content
While dimensions describe attributes of individual rows, measures compute values across rows — sums, counts, averages, and other aggregations. Measures can aggregate columns directly (like sum of revenue) or reference other measures to create compound metrics (like revenue / count).
See the measures reference for the full list of parameters and configuration options.

Defining measures

A measure specifies the SQL expression to aggregate and the aggregation type:

Filtered measures

You can apply filters to a measure to create conditional aggregations. Only rows matching the filter are included:
When completed_count is queried, Cube generates SQL with a CASE expression:

Calculated measures

Calculated measures perform calculations on other measures using SQL functions and operators. They provide a way to decompose complex metrics (e.g., ratios or percents) into formulas involving simpler measures.

Referencing measures in the same cube

Referencing measures from other cubes

If cubes are joined, you can reference measures across cubes. Cube generates the necessary joins automatically:

Multi-stage measures

Multi-stage measures are calculated in two or more stages, enabling calculations on already-aggregated data. Each stage results in one or more CTEs in the generated SQL query.
Multi-stage measures are powered by Tesseract, the next-generation data modeling engine. In versions before v1.7.0, it was not enabled by default.

Rolling windows

Rolling window measures calculate metrics over a moving window of time, such as cumulative counts or moving averages. Use the rolling_window parameter:

Period-to-date

Period-to-date measures analyze data from the start of a period to the current date — year-to-date (YTD), quarter-to-date (QTD), or month-to-date (MTD):

Time shift

Time-shift measures calculate the value of another measure at a different point in time, typically for period-over-period comparisons like year-over-year growth. Use the time_shift parameter:
You can combine time shift with period-to-date for comparisons like “this year’s YTD vs. last year’s YTD”:
Time-shift measures can also be used with calendar cubes to customize how time-shifting works, e.g., to shift by retail calendar periods.

Percent of total (fixed dimension)

Use the grain parameter with keep_only to fix the inner aggregation to specific dimensions, enabling percent-of-total calculations:

Share of total (filter override)

Use the filter parameter to override the filters that a multi-stage measure inherits from the query. This enables “share of total” calculations where the denominator must ignore a filter applied by the query. In the example below, amount_all_statuses uses exclude to drop the status filter, so it always aggregates across all statuses. When the query is filtered to a single status, total_amount reflects that status while amount_all_statuses stays the full per-category total, and percent_of_total is the share that the filtered status represents:

Nested aggregates

Use the grain parameter with include to compute an aggregate of an aggregate, e.g., the average of per-customer averages:
When a nested aggregate combines two or more other multi-stage measures that share the same grain, set grain on the combining measure — not on each of its inputs. For example, to average a per-day ratio, group the per-day components by day through the combining measure:
grain fixes the inner grain of the measure it’s declared on and does not expose the added dimension to a measure built on top of it. If each input measure declares the same grain.include (rather than the combining measure), the inputs no longer carry a shared grouping key, so they are combined with a cross join instead of being joined on that key — producing incorrect results. Declare grain on the combining measure so its inputs are joined on the shared grain.

Ranking

Use the grain parameter with exclude to rank items within groups:
grain replaces the standalone group_by, reduce_by, and add_group_by parameters, which remain supported. See the grain reference for the migration mapping.

Conditional measures

Conditional measures depend on the value of a dimension, using the case parameter with switch dimensions:

Formatting

Use the format parameter to control how measures are displayed:

Next steps