Level 1: Model the data

Confident wrong answers

Your AI tool isn't wrong. Your model is.

A small example with made-up numbers, where the same rows give 100.00, 200.00 or 400.00, and nothing errors.

Updated November 2026Example data, not from a client.
On this page
  1. Two tables
  2. The join that looks fine
  3. Catch it with a row count
  4. Two fixes that don't work
  5. What works
  6. Two more traps
  7. What to write down
  8. What I check first

One customer, one product. In April 2025 there are two revenue rows: 120.00 and -20.00. April revenue is 100.00.

The same customer and product also have two recorded contract terms. Both tables carry customer and product keys, so someone joins them on those keys. Point AI tools or a coding agent at that model and it can hand you the wrong total with total confidence. It reads the model you gave it.

Two tables, one customer, one product

Revenue
PKidFKcustomerFKproductreporting_dateaccounting_dateamount
R-001C-001P-012025-04-012025-05-01120.00
R-002C-001P-012025-04-012025-04-01-20.00
R-003C-001P-012025-05-012025-05-01300.00

Revenue. One row per recognized revenue entry.

Terms
PKidFKcustomerFKproductterm_startterm_endamount
T-001C-001P-012024-04-012025-03-312,500.00
T-002C-001P-012025-04-012026-03-310.00

Terms. One row per recorded contract term.

The question: what was April 2025 revenue for this customer and product, by reporting date? The correct answer is 120.00 + (-20.00) = 100.00.

The join that looks fine

SELECT SUM(r.amount)
FROM revenue r
JOIN terms t
  ON t.customer = r.customer
 AND t.product  = r.product
WHERE r.reporting_date >= '2025-04-01'
  AND r.reporting_date <  '2025-05-01';

Each revenue row matches both terms, so you get four rows: 120, 120, -20, -20. Total: 200.00. No error, no warning.

This happens wherever the join runs before the sum: a SQL query, a database view, a Power Query merge, a Tableau physical join, or a coding agent writing SQL against your warehouse. Power BI relationships and Tableau relationships aggregate each table before combining them, so they don't double this total. A direct fact-to-fact relationship still limits how you can filter and group, and Microsoft's guidance generally recommends against it.

Figure 1 · Same rows, joined twice

Fanout: how a join turns 100.00 into 200.00 Wrong path, when the join runs before the sum: the Revenue table rows R-001 (120.00) and R-002 (-20.00) are joined on customer and product to the Terms table rows T-001 and T-002. Each revenue row matches both terms, giving four joined rows (120, 120, -20, -20) that sum to 200.00. Right path: the same two revenue rows summed on their own, with no join, give 100.00. Both tables are fact tables, tagged FACT. WRONG · JOIN REVENUE TO TERMS Revenue FACT R-001 120.00 R-002 -20.00 Terms FACT T-001 2,500.00 T-002 0.00 Each revenue row matches both terms. R-001 × T-001 120.00 R-001 × T-002 120.00 R-002 × T-001 -20.00 R-002 × T-002 -20.00 4 rows summed 200.00 Same filter, twice the rows. No error. RIGHT · SUM REVENUE ON ITS OWN Revenue FACT R-001 120.00 R-002 -20.00 April, by reporting date. No join, so no extra rows. 2 rows summed 100.00
When the join runs before the sum, two revenue rows times two terms is four rows. The total doubles and nothing errors. Open full size
The term amounts have nothing to do with it. Change them to anything and you still get 200.00. The extra rows come from the match count, not the values.

Catch it with a row count

You don't need to know the right answer to catch this. You only need to count. Run the same filter twice, once without the join and once with it.

-- 1. Rows in scope before the join
SELECT COUNT(*) AS rows_before
FROM revenue r
WHERE r.reporting_date >= '2025-04-01'
  AND r.reporting_date <  '2025-05-01';

-- 2. The same rows after the join
SELECT COUNT(*) AS rows_after
FROM revenue r
JOIN terms t
  ON t.customer = r.customer
 AND t.product  = r.product
WHERE r.reporting_date >= '2025-04-01'
  AND r.reporting_date <  '2025-05-01';

-- 3. Which rows multiplied, and by how much
SELECT r.id, COUNT(*) AS matches
FROM revenue r
JOIN terms t
  ON t.customer = r.customer
 AND t.product  = r.product
WHERE r.reporting_date >= '2025-04-01'
  AND r.reporting_date <  '2025-05-01'
GROUP BY r.id
HAVING COUNT(*) > 1;

Here the first query returns 2 and the second returns 4. The third lists R-001 and R-002 with 2 matches each. If the count after a join is higher than the count before it, that join is multiplying the rows you're about to sum. Stop there and fix the model before anyone, or anything, reads the total.

Two fixes that don't work

  • SUM(DISTINCT amount). Two real revenue entries can have the same amount. You'd silently drop one.
  • "Just pick one term." MIN(id), the latest row, whichever comes first: any rule you make up links a revenue entry to a term with no business rule behind it. If the business really does tie revenue to the term in force on the reporting date, that's a different thing. Write the rule down, join on the date range (term_start to term_end), and test that every revenue row matches exactly one term.

What works

Answer each question from its own table. Revenue comes from Revenue. Term detail comes from Terms. If you need them on one page, put them side by side and filter both from shared Customer and Product dimensions. Kimball calls these conformed dimensions: one Customer table and one Product table, with the same keys and the same meaning, shared by every fact table that uses them.

In Power BI, that means two fact tables, each related one-to-many from Customer and Product, with no relationship between the facts. In Tableau 2024.2 or later, it's a multi-fact relationship model: Revenue and Terms as base tables, Customer and Product as shared tables. In a dbt semantic layer, it means two semantic models that each reference Customer and Product as foreign entities, plus a Customer and a Product semantic model that declare those keys as primary entities. dbt says a primary key "must contain unique values and can't contain null values" (dbt: Entities). Revenue and terms then only meet through those shared dimensions.

Figure 2 · The shape that stops it

Model shape as ERDs: fact joined to fact versus shared dimensions Wrong: the Revenue table (PK id, FK customer, FK product, reporting_date, accounting_date, amount) is joined straight to the Terms table (PK id, FK customer, FK product, term_start, term_end, amount) on customer and product, many to many, which multiplies rows. Right: a Customer table (PK customer) and a Product table (PK product) each relate one-to-many (exactly one to zero or many) to both Revenue and Terms, and there is no line between the two fact tables. The same shape applies in Power BI, Tableau or a dbt semantic layer. Fact tables have dark headers tagged FACT and dimension tables have green headers tagged DIM. A legend shows the three line-end marks: exactly one, zero or many, and one or many. WRONG · FACT JOINED TO FACT Revenue FACT PK id FK customer FK product reporting_date accounting_date amount Terms FACT PK id FK customer FK product term_start term_end amount Joined on customer + product. Many to many, so rows multiply. RIGHT · SHARED DIMENSIONS Customer DIM PK customer Revenue FACT PK id FK customer FK product reporting_date accounting_date amount Terms FACT PK id FK customer FK product term_start term_end amount Product DIM PK product No line between Revenue and Terms. exactly one zero or many one or many
Labels are generic on purpose. The same shape works in Power BI, Tableau or a dbt semantic layer. Open full size

The same fix in SQL

If you need revenue and term detail in one result, total each table on its own first. Combine them only once each side is down to one row per customer and product.

WITH rev AS (
  SELECT customer, product,
         SUM(amount) AS april_revenue
  FROM revenue
  WHERE reporting_date >= '2025-04-01'
    AND reporting_date <  '2025-05-01'
  GROUP BY customer, product
),
trm AS (
  SELECT customer, product,
         COUNT(*) AS term_count
  FROM terms
  GROUP BY customer, product
)
SELECT rev.customer, rev.product,
       rev.april_revenue, trm.term_count
FROM rev
LEFT JOIN trm
  ON trm.customer = rev.customer
 AND trm.product  = rev.product;

Result: one row. C-001, P-01, April revenue 100.00, 2 terms. Each side has one row per customer and product before they meet, so the join has nothing to multiply.

Two more traps in the same three rows

  • Leave the date filter off the correct query, the one with no join, and you get 400.00, because May's 300.00 comes in. With no date filter you're asking for all time. Here that happens to be 2025, because every row is in 2025, but it's still wrong for April. Drop the date filter from the join query above and you get 800.00: both mistakes at once.
  • Switch to accounting date and April is -20.00, because R-001 is booked to May on that basis. Both 100.00 and -20.00 are correct answers to different questions. The report has to say which date it uses.

Figure 3 · Which date?

Which date: one question, three answers The question is April 2025 revenue for customer C-001 and product P-01. By reporting date the answer is 100.00 from R-001 and R-002, which answers revenue reported in April. By accounting date it is -20.00 from R-002 only, because R-001 is booked to May; that answers revenue booked to April, a different question. With no date filter and no join it is 400.00 from all three rows, which answers all time (here, only 2025) and is wrong for April. ONE QUESTION April 2025 revenue for C-001, P-01 BY REPORTING DATE 100.00 Rows: R-001, R-002 Answers: revenue reported in April. RIGHT for this question BY ACCOUNTING DATE -20.00 Rows: R-002 (R-001 is booked to May) Answers: revenue booked to April. Right, but a different question NO DATE FILTER, NO JOIN 400.00 Rows: R-001, R-002, R-003 Answers: all time (here, only 2025). WRONG for April
All three numbers come from the same three rows. Only the date rule changes. Open full size

What to write down for any tool that reads your model

A dashboard, a semantic layer and an AI tool all read the same model. None of them can see the rules in your head. For each fact table, write down three things: what one row means, which date each measure uses, and which joins are allowed. Here is what that looks like for this example.

# Revenue
one_row_means: one recognized revenue entry
primary_key: id
foreign_keys: customer -> Customer,
  product -> Product
default_date: reporting_date
other_dates: accounting_date (its own
  measure, named as such)
joins_allowed: Customer, Product
never_join_to: Terms

# Terms
one_row_means: one recorded contract term
primary_key: id
foreign_keys: customer -> Customer,
  product -> Product
dates: term_start, term_end (describe the
  term, not revenue)
joins_allowed: Customer, Product
never_join_to: Revenue
not_revenue: amount is a term amount,
  never summed as revenue

Keep it wherever your tool reads descriptions: table and column descriptions in the model, your semantic layer's definitions, or a short README next to the model. The format matters less than having it written down in one place.

What I check before any tool answers from a model

  1. What does one row mean in each fact table?
  2. Does any join change the row count of the table being summed? Compare row counts before and after.
  3. Which date does each measure use, and does the report say so?
  4. What happens with no rows, with a zero, and with an unknown date? Those should be three different results, not all blank or all zero.

Check the grain first. Then ask the question.

About to put AI on a Power BI model?

I review one model, fixed scope, and tell you what to fix first.

See the model review

Privacy

Related