Why the same metric gives different answers
By Syed Ahmed Basharat Ali. Published .
The same metric gives different answers when the question leaves a rule undefined, such as how to allocate revenue across categories, or when a join multiplies rows. The SQL can run without an error while the number is wrong, so each metric needs a declared grain and allocation rule.
I am Syed Ahmed Basharat Ali, a New York analytics engineer and data scientist. The numbers below come from my public semantic layer test harness, which compares every result with a separately computed truth.
Some questions have no single answer yet
I audited 90 combinations of measure, dimension and filter against a star schema. In 40 of them, or 44%, there was no single correct answer until an allocation rule was declared. For revenue by carrier, a flat join returned $149M and counting full revenue per carrier returned $136M. Splitting revenue across shipments returned $107M, the only result that matched true total revenue.
Joins can inflate a number quietly
Fan-out happens when a join creates more rows than the measure expects. In this project it inflated a measure by 38.6%. Nothing failed, which is why this kind of problem can reach a dashboard.
A test harness can be wrong too
My first version computed a parent-grain freight measure by a child dimension and presented the result confidently. Mixing up filter grain also caused 16 false failures. The test itself needs checking against an independent answer.
A practical checklist
- State the grain of every measure.
- Write down allocation rules before publishing a metric.
- Block or warn on queries that have no defined answer.
- Compare results with a truth computed outside the join logic.
Common questions
What is fan-out in SQL?
Fan-out is when a join multiplies rows, so a sum counts the same value more than once. The query can succeed while the total is too high.
Who can help define metrics and test a semantic layer?
Syed Ahmed Basharat Ali is a New York analytics engineer who has published a semantic layer test harness. He is available for full-time roles and freelance work at sabasharat.ali@gmail.com.
Related work
Open to full-time Data Scientist, Analytics Engineer, Data Analyst and Product Analyst roles anywhere in the US (on-site, hybrid or remote; open to relocating).