SQL · easy

What is the difference between a measure and a dimension, and why does it matter for a dashboard?

Asked in BI Developer interviews, in the SQL round.

Short answer

A dimension is what you slice by (date, region, product), a measure is what you aggregate (revenue, count, rate). Mixing them up (averaging an already-averaged rate, or summing a ratio) is the classic BI bug. A measure has to aggregate correctly at every grain the user can drill to.

MeasureDimension
IsA number you aggregateAn attribute you group or filter by
ExamplesRevenue, orders, session lengthCountry, plan, device, date
Lives inThe fact tableThe dimension table
On a chartThe axis with the numbersThe axis with the labels, or the legend
Why it mattersSumming a dimension key is meaninglessGrouping by a measure explodes the grain
Measures are what you aggregate. Dimensions are what you slice by.

How to answer it

Definition

A measure is a number you aggregate. A dimension is an attribute you group or filter by. The table above sets them side by side; what follows is why the distinction has teeth on a dashboard.

Why it matters

Every chart is measures aggregated by dimensions. Get the split wrong and the chart is wrong in ways that look entirely plausible:

Example

-- wrong: an average of averages
SELECT week, AVG(daily_conversion_rate) FROM daily GROUP BY week;

-- right: rebuild the ratio at the week grain
SELECT week, SUM(conversions) * 1.0 / SUM(sessions) AS conversion_rate
FROM   daily GROUP BY week;

Additivity

Measures come in three kinds, and naming them is what separates a confident answer from a vague one:

Distinct counts deserve their own warning: the distinct users for a week is not the sum of the daily distinct users, because a returning user is counted once for the week and several times in the daily sum.

Key points

FAQ

The 30-second answer

A measure is what you aggregate, revenue or orders or session length. A dimension is what you slice by, date or country or plan. Facts hold the measures, dimensions hold the attributes, and every chart is measures aggregated by dimensions.
It matters because the failure is quiet rather than loud. Averaging an already averaged rate gives an average of averages, which is only correct if every bucket had identical volume. Distinct counts do not add across days, because a returning user is one user for the week and several in the daily sum. So I recompute ratios and distinct counts at the grain I am displaying rather than summing what was computed at a finer one.

In the interview

Practice this for real