When would you use this?
- Operations asks “Which trucks have the highest average daily sales?” - not the total, but the daily average, so high-volume trucks aren’t just rewarded for operating more days.
- You need a metric that says average daily revenue per country when sliced by country, but average daily revenue per truck when sliced by truck - same metric, adaptive grouping.
- Finance wants to compare daily performance across regions that operate different numbers of days.
What this recipe builds
Two metrics demonstrating the dynamic grouping pattern. The inner metric usesGROUP BY (*, order_header.order_date) - the
* means whatever the user is grouping by, plus date - so the
inner SUM always computes daily totals regardless of the outer
dimension. The outer AVG then averages those daily values.
Steps
1
Daily revenue (inner)
Revenue grouped by user context plus date. The
* inherits
whatever dimension the user is querying. This is the building
block for the average daily revenue metric.- SQL
- YAML
2
Average daily revenue
Average revenue per day. Grouped by truck = average daily per
truck. Grouped by country = average daily per country. One
metric, any slicing.
- SQL
- YAML
Example - sliced by country
Each row shows the average revenue per day for that country.
Australia and Germany lead with similar daily averages despite
potentially different total revenues - the daily average
normalizes for operating days.
Key design notes
Related reading
- Dynamic grouping -
reference on
GROUP BY (*, entity.field)