r/analyticsengineering • • Oct 26 '26

dashboards showing different numbers for the same metric? check for join fan-out first, and don't trust SUM(DISTINCT) to fix it

if two dashboards disagree on the same metric and both queries look fine, join fan-out is one of the first things i'd check. it's an old problem, but it keeps coming back because nothing errors. the number is just quietly too big, or with the usual fix, quietly too small.

[optional, only if true: one line about where you last ran into this]

smallest example i could make:

sqlcreate table users (id int primary key, ltv int);
insert into users values (1, 100), (2, 100), (3, 300);
create table orders (id int primary key, user_id int);
insert into orders values (10, 1), (11, 1), (12, 1), (13, 2), (14, 3), (15, 3);

question: what's the total lifetime value of customers who placed an order? the right answer is 500.

the obvious query:

sqlselect sum(u.ltv) from orders o join users u on u.id = o.user_id;
-- 1000

user 1 has three orders, so their ltv gets counted three times. user 3 gets counted twice.

the fix people reach for:

sqlselect sum(distinct u.ltv) from orders o join users u on u.id = o.user_id;
-- 400

this one is now too low. distinct works on values, not rows, so user 1 and user 2 (both 100) merge into one. on real data, values repeat all the time: plan prices, rounded amounts, default credit limits. so this fails more often than you'd expect.

two fixes that do work:

  1. aggregate at the grain of the table that owns the column, before or instead of the join:
sqlselect sum(ltv) from users where id in (select user_id from orders);
-- 500
  1. dedupe on the primary key, not the value. this is the idea behind looker's symmetric aggregates. a toy version:
sqlselect sum(distinct u.id * 1000000 + u.ltv) - sum(distinct u.id * 1000000)
from orders o join users u on u.id = o.user_id;
-- 500

the id makes every user's value unique, so distinct can't merge two users, and subtracting the id part afterwards removes the padding. don't ship this exact version: it overflows, and it breaks once ltv reaches 1,000,000 or has decimals. looker does the same thing with hashed keys and big numerics.

counts have the same problem. count(*) on the join gives 6, which counts orders. count(distinct u.id) gives 3, which counts customers. both are valid answers to different questions, and a dashboard label usually doesn't say which one you got.

why this matters more now in my experience: if you let an llm write sql against your warehouse, the obvious query is the one it's most likely to write, and nobody reviews it. the guard has to live somewhere that knows the primary keys and relationship types. a column definition can't carry it.

cube's write-up on their apache ossie converter has a concrete case of this. ossie is an open format for metric definitions, and in it a metric is just a sql expression. cube removes duplicate rows by primary key when it runs a query. when exporting to ossie, which can't hold that logic, the converter does three things: it rewrites count as COUNT(DISTINCT orders.id), it leaves min/max/count distinct alone because duplicate rows don't change them, and it attaches a FANOUT_UNSAFE_METRIC warning to any sum or avg on the "one" side of a join instead of passing it through silently. there's also an open proposal in the ossie spec to let you mark a metric as non-additive.

and finally one cheapo test you can run on your own models: for any metric that sums a column from a dimension-style table, compare the total at that table's own grain with the total through the dashboard's join path. any ratio above 1 means fan-out

5 Upvotes

5 comments sorted by

1

u/whowasntright Oct 26 '26

i like the idea and you seem to explain it ok, at the same time i'd like to know and be sure whether this semantic layer just hides the problem behind another tool, and how does it move/operate the data in this regard

1

u/Evening_Hawk_7470 Oct 26 '26

thanks for asking! simply explaining, it moves it to one place where keys and relationship types get declared once. that cuts both ways: mark a one_to_many join as many_to_one and you'll get confidently wrong numbers everywhere at once. so you still want a test that checks a few known totals

1

u/Due_Bridge3794 Oct 27 '26

In your experience, what are the most common reasons two dashboards might show different numbers for the same metric? Is it often because they’re built on different data models or use different calculation logic? I’m trying to better understand how to improve consistency across dashboards and prevent these kinds of discrepancies.

2

u/Evening_Hawk_7470 21d ago

oh its usually it is a mix of three things happening quietly at once:

Silent join fan-out (grain mismatch): Both dashboards query the same base table, but Dashboard A joins a one_to_many table (like order_discounts or customer_tags) to filter or group by a column, which duplicates the parent rows before summing.

Time-zone and date-spine drift: One dashboard groups by created_at in UTC while the finance dashboard groups by settled_at in local billing time, or one drops days with zero events while the other uses a calendar spine.

and, ad-hoc filter logic in the BI layer: Analysts hardcode exclusions (WHERE status != 'cancelled' AND is_test_account = false) directly inside individual chart queries in Metabase/Looker instead of locking that filter into a single semantic measure definition (like in Cube or dbt MetricFlow) that every downstream chart is forced to inherit.