Sub topic 9
Totals and double counting
This chapter assumes you can build a bridge table, set relationships in model view, and write basic CALCULATE measures. Here you will see why a many-to-many model can show row values that do not add up to the total, and how to check for it.
Why the rows exceed the total
Take one account, A1, with 100 in transactions. Two customers share it: C1 and C2. The bridge table holds the pairs (A1, C1) and (A1, C2).
A table visual with Customer on rows and Amount via Bridge as the value shows:
| Customer | Amount via Bridge |
|---|---|
| C1 | 100 |
| C2 | 100 |
| Total | 100 |
Each row is correct, because both customers really do have access to account A1. The total row has no customer filter, so it counts the transaction once, and 100 is also correct. The rows add up to 200, which is the double counting. Nothing is broken. The values are non-additive because one transaction belongs to more than one row.
Measuring the overlap
The base measure is a plain sum on the fact table:
Total Amount = SUM ( Transactions[Amount] )The filtered measure uses the bridge, with bidirectional filtering turned on for one calculation:
Amount via Bridge =
CALCULATE (
SUM ( Transactions[Amount] ),
CROSSFILTER ( AccountBridge[AccountID], Accounts[AccountID], BOTH )
)Rows Check compares the sum of the visible rows with the true grand total:
Rows Check =
VAR GrandTotal = CALCULATE ( [Total Amount], ALL ( Customers ) )
VAR VisibleSum = SUMX ( VALUES ( Customers[CustomerID] ), [Amount via Bridge] )
RETURN VisibleSum - GrandTotalIn the example, VisibleSum is 200 and GrandTotal is 100, so the check returns 100. That is the amount counted more than once. If each account belongs to only one customer, the result is 0.
Reading the result
- 0: the rows add up to the total, so there is no overlap in the current selection.
- A positive number: shared accounts are counted under several customers. This is expected for a true many-to-many model.
- A negative number: some transactions are not reached by any visible customer. Check for accounts that are missing from the bridge.
Deciding what the total should show
Because the rows legitimately overlap, you choose which number the total row should display.
- Keep the true total. The total row shows each transaction once. This suits questions such as "how much money moved overall?". Label the visual so readers know the rows overlap.
- Show the sum of the rows. Wrap the measure in
SUMXover the customer column, asRows Checkdoes. This suits questions such as "how much exposure does each customer have?". It overstates the company-wide amount. - Remove the overlap with weights. Add an allocation weight to the bridge so each shared transaction is split across its customers and the rows sum to the total. A later chapter covers this.
Common mistakes
- Duplicate pairs in the bridge. Duplicates add extra rows to the many side and can inflate every figure. Build the bridge with
DISTINCT, as shown in the previous chapter. - Comparing a customer-filtered measure with
Total Amount. The two answer different questions, so a difference between them is expected. - Testing only one customer. With a single customer selected the check returns 0, so the overlap stays hidden.
Exercise
Account A1 has 100 in transactions and belongs to customers C1 and C2. Account A2 has 50 and belongs only to C1. A visual shows Customer and Amount via Bridge. What are the three values in the C1 row, the C2 row, and the Total row, and what does Rows Check return?
Show answer
C1 shows 150 (A1 plus A2), C2 shows 100 (A1), and the Total shows 150 (each transaction once). The visible sum is 250 and the grand total is 150, so Rows Check returns 100, the amount of A1 counted twice.