shuffleet
Home
Practice
Problems
Lessons
Plans
Compete
Challenges
Interviews
Leaderboard
Progress
Skills
Analytics
Submissions
Account
Settings

Additive vs. non-additive measures

Intermediate · 4 min read

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:

dayrevenueordersunique usersusers
Mon30032{ana, ben}
Tue20022{ben, cleo}
questionsum the tabletrue answer
revenue Mon–Tue500500 ✓
orders Mon–Tue55 ✓
unique users Mon–Tue43 ✗ (ben counted twice)
kindexamplerule
additiverevenue, order count, quantitysum across anything
semi-additiveaccount balance, stock on handsum across accounts or products, not across time (take end of period)
non-additivedistinct count, average, conversion ratenever sum; rebuild from parts

Revenue adds up across days; unique users don't, because ben is counted on both days

In SQL

Averages and ratios: store the parts, divide at the end.

SQL
-- 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:

SQL
-- 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 levelthe 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 rangethe detail at that grain (one row per user per day) and count distinct from it
distinct counts over any range, fast, approximation OKa sketch per row (HyperLogLog) and merge
balances, stock levelsthe 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.