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: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.Rolling windows
Rolling window measures calculate metrics over a moving window of time, such as cumulative counts or moving averages. Use therolling_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 thetime_shift parameter:
Percent of total (fixed dimension)
Use thegroup_by parameter to fix the inner aggregation to
specific dimensions, enabling percent-of-total calculations:
Share of total (filter override)
Use thefilter 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 theadd_group_by parameter to compute an aggregate
of an aggregate, e.g., the average of per-customer averages:
Ranking
Use thereduce_by parameter to rank items within groups:
Conditional measures
Conditional measures depend on the value of a dimension, using thecase parameter with switch dimensions:
Formatting
Use theformat parameter to control how measures are displayed:
Next steps
- See the measures reference for all parameters
- Learn about dimensions for grouping and filtering
- Explore pre-aggregations to accelerate measure queries
- See the period-over-period recipe for advanced time comparisons