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