Rolling
Calculate rolling window aggregations (7-day average, 30-day sum, etc).
Overview
Rolling window measures aggregate data over a sliding time period. Use rolling_window to define moving averages, cumulative totals, and time-based comparisons.
Example
measures:
- name: rolling_7_day_orders
type: count
rolling_window:
trailing: 7 day
offset: start
- name: rolling_30_day_revenue
type: sum
sql: amount
rolling_window:
trailing: 30 daySyntax
rolling_window Properties
| Property | Description |
|---|---|
trailing | Time period to look back (e.g., 7 day, 1 month) |
leading | Time period to look forward (rare) |
offset | start or end — which end of the window to align |
Trailing Window
- name: rolling_7_day_avg
type: avg
sql: amount
rolling_window:
trailing: 7 dayCumulative (Running Total)
Use unbounded for cumulative calculations:
- name: cumulative_revenue
type: sum
sql: amount
rolling_window:
trailing: unboundedOffset Options
# Window ends at current row (default)
rolling_window:
trailing: 7 day
offset: end
# Window starts at current row
rolling_window:
trailing: 7 day
offset: startCommon Patterns
7-Day Moving Average
- name: daily_orders
type: count
- name: rolling_7_day_avg_orders
type: avg
sql: "\{daily_orders\}"
rolling_window:
trailing: 7 dayMonth-to-Date
- name: mtd_revenue
type: sum
sql: amount
rolling_window:
trailing: 1 month
offset: startYear-to-Date
- name: ytd_revenue
type: sum
sql: amount
rolling_window:
trailing: 1 year
offset: startRequirements
- Rolling window measures require a time dimension in the query
- Works best with pre-aggregations for performance
See Also
- cubes.measures
- cubes.measures.calculated
- cubes.dimensions.time
- pre-aggregations