In two sentences
Some numbers can be added up across any slice: revenue for Monday plus revenue for Tuesday is revenue for both days. Others can't: unique users, averages and ratios give a wrong answer when you add or average them, and that decides what you can safely pre-aggregate.
See it
A daily summary table:
| day | revenue | orders | unique users | users |
|---|---|---|---|---|
| Mon | 300 | 3 | 2 | {ana, ben} |
| Tue | 200 | 2 | 2 | {ben, cleo} |
| question | sum the table | true answer |
|---|---|---|
| revenue Mon–Tue | 500 | 500 ✓ |
| orders Mon–Tue | 5 | 5 ✓ |
| unique users Mon–Tue | 4 | 3 ✗ (ben counted twice) |
| kind | example | rule |
|---|---|---|
| additive | revenue, order count, quantity | sum across anything |
| semi-additive | account balance, stock on hand | sum across accounts or products, not across time (take end of period) |
| non-additive | distinct count, average, conversion rate | never sum; rebuild from parts |
In SQL
Averages and ratios: store the parts, divide at the end.
-- daily table keeps the additive parts
SELECT day, sum(amount) AS revenue, count(*) AS orders FROM ...
-- average order value for the month: sum the parts first
SELECT sum(revenue) / sum(orders) AS avg_order_value
FROM daily_orders
WHERE day BETWEEN DATE '2026-04-01' AND DATE '2026-04-30';avg(revenue / orders) over days gives every day the same weight, however many orders it had. That's a different
(usually wrong) number.
Distinct counts: either keep the detail (one row per user per day) and count distinct from it, or store a sketch that can be combined. In Trino, a HyperLogLog sketch:
-- daily: store a sketch of the users, not their count
SELECT day, CAST(approx_set(user_id) AS varbinary) AS users_sketch
FROM page_views GROUP BY day;
-- any range: merge the sketches, then count
SELECT cardinality(merge(CAST(users_sketch AS HyperLogLog))) AS unique_users
FROM daily_users
WHERE day BETWEEN DATE '2026-04-01' AND DATE '2026-04-30';It's approximate (around 2% error by default) and that's the trade: exact needs the detail rows.
When to use it
Every time you design a fact table, an aggregate table or a dashboard: list each measure and write its kind next to it. That list decides what the table must store.
| you need… | store |
|---|---|
| sums and counts at any level | the additive measures at the lowest grain you can afford |
| ratios and averages (conversion, AOV, margin %) | the numerator and denominator, never only the ratio |
| exact distinct counts over any range | the detail at that grain (one row per user per day) and count distinct from it |
| distinct counts over any range, fast, approximation OK | a sketch per row (HyperLogLog) and merge |
| balances, stock levels | the end-of-period value, and a rule for rolling up time (last value, or average daily balance) |
Best practices
- Pre-aggregate for known, repeated questions (a dashboard). Keep the detail for ad-hoc questions.
- Define metrics once, in one place (a metrics or semantic layer, or a documented view) with how each one rolls up, so BI tools can't sum what shouldn't be summed.
- Label approximate numbers as approximate where people read them.
- Decide exact vs. approximate by who reads it: finance and billing need exact; product trends rarely do.
Common mistakes
- Summing a daily distinct count to get a weekly or monthly one. The most common dashboard bug.
- Averaging averages. Average order value by country, averaged across countries, ignores that France had 10× the orders.
- Summing a balance across months. Three month-end balances of 100 is not 300 in the account.
- Pre-aggregating too early. Once you've thrown away the user ids, the distinct count can't be recovered.
What an interviewer asks next
- "The dashboard is slow. Pre-aggregate it without breaking the numbers." Name each measure's kind, keep parts for ratios, sketches or detail for distinct counts.
- "Is a sketch good enough for finance?" No: finance wants exact. For product analytics, usually yes.
Go further
The Kimball page is the canonical one-screen definition of the three kinds. The Trino page shows every HyperLogLog function.
Practise it
Pre-Aggregate a Slow Dashboard Without Breaking Distinct Counts (hard) is this lesson end to end.