Sub topic 9
Totals and double counting
This chapter assumes you can build a one-to-many relationship, set a cross-filter direction, and write a measure with SUM and CALCULATE. It also assumes you have a bridge table wired between two dimensions, as in the previous chapters. Here you will see why a many-to-many model produces row values that add up to more than the total, decide whether that is a bug, and learn how to control what the total row shows.
Why the numbers stop adding up
In a one-to-many model, each fact row belongs to exactly one member of a dimension. A customer breakdown therefore partitions the data. Every transaction lands in one row, so the rows add up to the total.
A many-to-many relationship breaks that rule. If one account has two owners, its transactions belong to both. Each owner's row correctly includes the account, and the total counts the account once.
Here is a small model. Ann and Ben share account A1. Ann also owns A2, and Ben also owns A3.
The transactions total 180. The customer rows work out like this:
| Customer | Accounts reached | Amount via Bridge |
|---|---|---|
| Ann | A1, A2 | 150 |
| Ben | A1, A3 | 130 |
| Sum of rows | 280 | |
| Total row | A1, A2, A3 | 180 |
The rows sum to 280, but the real money is 180. The difference of 100 is account A1, counted once for each owner.
What the total row calculates
A measure does not add up the rows above it. It is evaluated again in the filter context of each cell. For the total row, no customer is selected. The Customers table is unfiltered, so the bridge is unfiltered, and every account is visible. The measure then sums every transaction once.
Use the base measure and the bridge measure from earlier:
Total Amount = SUM ( Transactions[Amount] )Amount via Bridge =
CALCULATE (
SUM ( Transactions[Amount] ),
CROSSFILTER ( AccountBridge[AccountID], Accounts[AccountID], BOTH )
)In the matrix, the Customers column is on rows and both measures are in values. The results look like this:
| Row | Total Amount | Amount via Bridge |
|---|---|---|
| Ann | 180 | 150 |
| Ben | 180 | 130 |
| Total | 180 | 180 |
Total Amount ignores the customer because no relationship carries the filter from Customers to Transactions. It repeats 180 on every row. Amount via Bridge filters correctly, but its total is not the sum of its rows.
Both behaviors are correct for the questions they answer. "How much did Ann's accounts handle?" is 150. "How much money moved overall?" is 180. The problem appears when a report presents the two side by side without saying which question each number answers.
Three ways to handle the total row
You can choose among three behaviors, depending on what the report reader needs.
Keep the de-duplicated total
This is the default. The total is the true amount across all selected accounts, and each account is counted once. Choose it when the total feeds a financial figure or is compared against a source system.
Add a note to the visual, such as "Customer rows overlap because accounts can have several owners." This takes one line and prevents many support questions.
Hide the total
If readers will compare the total with the rows, remove the confusion by blanking the total. ISINSCOPE returns true when the cell is a row for a specific customer and false on the total row.
Amount via Bridge (rows only) =
IF (
ISINSCOPE ( Customers[CustomerID] ),
[Amount via Bridge]
)A measure that returns BLANK() for a cell makes that cell empty in a matrix. Turning off totals in the visual's formatting pane has a similar effect, but it applies to every measure in the visual. The measure approach lets you blank one column and keep the total on another.
Sum the rows deliberately
Sometimes the sum of rows is the right answer. An example is "total exposure per customer", where each customer is a separate relationship and the overlap is meaningful. Write that as an explicit iterator over the visible customers:
Amount Summed over Customers =
SUMX (
VALUES ( Customers[CustomerID] ),
[Amount via Bridge]
)VALUES returns the customers visible in the current context. On a row, that is one customer. On the total row, it is all customers, so each one's amount is added, and A1 is counted twice. Name this measure so that readers do not mistake it for a revenue total.
Measuring the overlap
The overlap is the amount counted more than once. You can calculate it with the validation measure from the topic plan:
Rows Check =
VAR GrandTotal = CALCULATE ( [Total Amount], ALL ( Customers ) )
VAR VisibleSum = SUMX ( VALUES ( Customers[CustomerID] ), [Amount via Bridge] )
RETURN VisibleSum - GrandTotalGrandTotal removes any filter on Customers and sums every transaction once. VisibleSum adds each visible customer's bridged amount. The difference is the overcounted amount.
In the example, VisibleSum is 280 and GrandTotal is 180, so Rows Check returns 100. That equals account A1, which has two owners. If every account has exactly one owner, the result is 0.
Put this measure in a card visual with no customer filter applied. Two situations make the result misleading:
- On a single customer row,
VisibleSumis that customer's amount andGrandTotalis still the entire total. The measure returns a large negative number, which means nothing. - With a customer slicer active,
GrandTotalignores the slicer throughALL ( Customers ), whileVisibleSumrespects it. The difference then mixes overlap with the filtered-out amount.
Duplicate rows in the bridge
Double counting from shared accounts is expected. Double counting from duplicate bridge rows is a data problem. If the bridge contains the pair Ann and A1 twice, the relationships still filter by the set of matching values, so SUM over Transactions does not count the account twice. The duplicates still cause trouble:
- Any measure that uses
COUNTROWS ( AccountBridge )returns inflated counts. - A relationship that requires a unique key on the "one" side fails to load or switches to many-to-many.
- Later changes, such as adding a weight column, would apply the weight twice.
This is why the bridge is built with DISTINCT, as in the earlier chapter on building it. Check it by comparing the row counts:
Duplicate Bridge Rows =
COUNTROWS ( AccountBridge )
- COUNTROWS (
DISTINCT (
SELECTCOLUMNS (
AccountBridge,
"AccountID", AccountBridge[AccountID],
"CustomerID", AccountBridge[CustomerID]
)
)
)A result of 0 means every pair appears once.
Common mistakes
- Reading the grand total as a sum. The total row recomputes the measure. It is not an add-up of the visible rows.
- Comparing
Total AmountwithAmount via Bridgeper row.Total Amountis not filtered by customer, so it repeats the same figure on every row. - Averaging or counting across overlapping rows. A distinct count of accounts per customer behaves the same way. Ann and Ben each have two accounts, but the total shows three, not four.
- Using
SUMXover customers for a revenue figure. It reports 280 where the books show 180. - Fixing the overlap with a many-to-one relationship. If the data has shared accounts, forcing the relationship to one-to-many either fails to load or silently drops one owner. The model then understates one customer.
When the overlap is acceptable but one number must add up, the usual fix is an allocation weight, so that each owner receives a share of the account. A later chapter covers that technique.
Exercise
A bridge links customers to accounts. Customer Dana owns accounts X (200) and Y (100). Customer Eli owns account Y and account Z (50). Using Amount via Bridge, what does the matrix show for Dana, Eli and the total row? What does Rows Check return in a card with no customer filter?
Show answer
Dana reaches X and Y, so she shows 300. Eli reaches Y and Z, so he shows 150. The total row has no customer filter, so it counts accounts X, Y and Z once each, and shows 350. The rows sum to 450. Rows Check returns 450 - 350 = 100, which is the amount of account Y, counted once for each of its two owners.