Why Did a Report Total Increase After Adding a Detail Table?

A project report totals 12 planned hours. A developer adds a table of review comments so the report can show comment counts. The total becomes 36 hours even though nobody changed the plan. The new join has repeated the project-level value across detail rows.
This is a question of grain: what does one row represent at each stage of the query? Before changing the final formula or removing apparent duplicates, inspect how many rows each relationship produces.
State the grain of every input
Write a plain-language description for each table or dataset. One row might represent a project, a task, a comment or a status event. Identify the key that makes a row unique within that meaning.
The PostgreSQL table-expression documentation explains that an inner join creates a result row for each matching row on the other side. A one-to-many relationship can therefore repeat the first table's values without any database error.
That behavior is often correct. The problem appears when a measure belonging to one grain is summed as though it belongs to the joined grain. A successful query does not establish a meaningful business total.
Trace one record through the join
Choose a synthetic parent with a known number of detail records. Show the rows before and after the join, including both parent and detail identifiers. This makes repetition visible without relying on a large dashboard total.
Check whether the relationship is truly one-to-one, one-to-many or many-to-many. A key that looks unique in a small sample may not be unique in the full dataset. Validate the intended uniqueness rather than treating it as an assumption.
Include a parent with no matching detail. An inner join may remove it; an outer join may preserve it with missing detail values. That choice affects the report population as well as the arithmetic.
Illustrative hours-and-comments fixture
A fictional project P1 has 12 planned hours and three comments. Joining P1 to those comments produces three rows, each carrying the same 12-hour project value. Summing that repeated column gives 36, which is not the project's planned effort.
If the report needs one row per project, the team can first summarize comments to one row per project and then join that summary to the project table. The resulting row contains 12 planned hours and a comment count of three.
This is one appropriate design for the stated report grain. It is not a universal instruction to aggregate every detail table before joining; a report genuinely intended to show one row per comment has a different purpose.
Avoid a cosmetic distinct fix
Removing duplicate-looking rows can hide legitimate records. Two comments may have identical text while representing separate events. Likewise, summing distinct numeric values can discard two different projects that happen to have the same planned hours.
Use business keys and the intended grain to decide what is unique. Do not use equality of a displayed value as a substitute for identity. Record the reason for any deduplication rule separately from the join correction.
If several detail tables are joined at once, inspect the combined multiplication. Two independent sets of details can multiply each other, making the final total much larger than either individual relationship suggests.
Reconcile counts and measures separately
Test the number of output entities, the number of detail events and the measure total. These are different quantities. A query can get one right while getting another wrong.
Use the data-lineage guide to record where each measure originates and which transformations affect it. Include filters and missing-detail behavior in the same record.
Compare a small manually calculated fixture with the query result before running the corrected report across the full dataset. Then investigate any material difference from the previous output rather than assuming every change is an improvement.
Keep the grain visible in maintenance
Add the one-row meaning to the report definition and test names. When someone adds a new detail table, require the same cardinality check. This makes the original reasoning available to the next maintainer.
Accept the report when its population, row grain and measures agree with the stated question. The objective is not merely to restore an old total; it is to show that the total follows from the intended business records.
FutureOS is in prelaunch. Use this guide to prepare a concrete project discussion, and read the published introduction for the current project context.
Prepared with AI assistance for the FutureOS editorial series. Primary sources checked on October 23, 2026. Examples are illustrative; this article does not announce an available FutureOS feature or an independently reviewed assessment.



Comments