Level 1: Model the data
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.
On this page
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
| PKid | FKcustomer | FKproduct | reporting_date | accounting_date | amount |
|---|---|---|---|---|---|
| R-001 | C-001 | P-01 | 2025-04-01 | 2025-05-01 | 120.00 |
| R-002 | C-001 | P-01 | 2025-04-01 | 2025-04-01 | -20.00 |
| R-003 | C-001 | P-01 | 2025-05-01 | 2025-05-01 | 300.00 |
Revenue. One row per recognized revenue entry.
| PKid | FKcustomer | FKproduct | term_start | term_end | amount |
|---|---|---|---|---|---|
| T-001 | C-001 | P-01 | 2024-04-01 | 2025-03-31 | 2,500.00 |
| T-002 | C-001 | P-01 | 2025-04-01 | 2026-03-31 | 0.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
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
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?
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
- What does one row mean in each fact table?
- Does any join change the row count of the table being summed? Compare row counts before and after.
- Which date does each measure use, and does the report say so?
- 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.