Window Decorators
Moving averages, ranking, and window functions.
Overview
Window decorators enable window functions like moving averages, running totals, ranking, and lead/lag calculations.
Available Decorators
Moving Average
Calculate moving average over a window.
# Applied in query, not in model definition
# User selects "Moving Average" decorator
Running Total
Calculate running/cumulative total.
# Applied in query
Ranking
Rank values (rank, dense_rank, percent_rank).
# Applied in query
Lead/Lag
Access previous/next values.
# Applied in query
How It Works
Window decorators are applied at query time:
- User selects measure and window decorator
- Planner generates SQL with window function
- Returns windowed values
Use Cases
Moving Average
- type: measure
name: Revenue
data_type: decimal
expression:
sql: sum(amount)
# User applies "7-day moving average" decorator
# Returns: 7-day moving average of revenue
Running Total
# User applies "Running Total" decorator
# Returns: Cumulative sum over time
Ranking
# User applies "Rank" decorator
# Returns: Ranked values (1, 2, 3, ...)
Best Practices
- Use with date dimensions - Window functions often require ordering by date
- Document measures - Help users understand window options
- Test calculations - Verify window functions work correctly
Next Steps
- Learn about temporal decorators
- Explore contribution decorators
- Read about snapshot measures