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. Tesseract is currently in preview. Use the CUBEJS_TESSERACT_SQL_PLANNER environment variable to enable it.

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:
The filter parameter requires the Tesseract SQL planner (CUBEJS_TESSERACT_SQL_PLANNER=true).

Nested aggregates

Use the grain parameter with include to compute an aggregate of an aggregate, e.g., the average of per-customer averages:

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