Sub topic 14
Validating Results and Watching Performance
This chapter covers how to check that a many-to-many model returns correct numbers, and how to find out whether it is slow before users do. It assumes you have built the model from the earlier chapters. That means a bridge table, relationships with the right filter direction, and a measure such as Total Amount. You should be comfortable with CALCULATE, SUMX, and the Performance Analyzer pane in Power BI Desktop.
The model under test
The examples use four tables:
Customers(one row perCustomerID)Accounts(one row perAccountID)AccountBridge(unique pairs ofAccountIDandCustomerID)Transactions(one row per transaction, withAccountIDandAmount)
Relationships run from Customers to AccountBridge and from Accounts to AccountBridge. A third runs from Accounts to Transactions. The bridge-to-Accounts relationship is bidirectional, or the measure uses CROSSFILTER, so that a customer selection reaches Transactions.
The base measure and the bridge measure are:
Total Amount = SUM ( Transactions[Amount] )Amount via Bridge =
CALCULATE (
SUM ( Transactions[Amount] ),
CROSSFILTER ( AccountBridge[AccountID], Accounts[AccountID], BOTH )
)Why many-to-many results need checking
A wrong many-to-many model rarely produces an error. It produces a plausible number. The three usual failures are:
- Amounts counted once per customer, so totals are inflated.
- Amounts dropped because an account has no bridge row.
- Bridge duplicates that multiply rows.
Check each of these on purpose.
A worked example with known answers
Use a tiny data set where you can add up the answer by hand.
| AccountID | Customers | Amount |
|---|---|---|
| A1 | C1, C2 | 100 |
| A2 | C1 | 50 |
| A3 | C2 | 30 |
The true total is 180. Customer C1 owns A1 and A2, so C1 shows 150. Customer C2 owns A1 and A3, so C2 shows 130. The sum of the customer rows is 280. A table visual with customers on rows therefore shows 150, 130, and a total of 180.
This is correct behavior, not a bug. The total row filters Transactions through the set of visible accounts, and A1 is only in that set once. The customer rows are not additive, because A1 counts toward both customers. Validation means confirming that this is the only source of the gap.
Measuring the overlap with Rows Check
Rows Check turns that gap into a number:
Rows Check =
VAR GrandTotal = CALCULATE ( [Total Amount], ALL ( Customers ) )
VAR VisibleSum = SUMX ( VALUES ( Customers[CustomerID] ), [Amount via Bridge] )
RETURN
VisibleSum - GrandTotalSUMX visits each visible customer and adds the bridge measure for that customer. Context transition applies the customer as a filter. For the sample data the result is 280 − 180 = 100, which is exactly the amount of A1.
Read the result like this:
- Zero: every account belongs to one customer, or only one customer is visible.
- Positive: some amount is shared across customers. The value is the amount counted more than once.
- Negative: some transactions are not reachable through the bridge. These are usually accounts that have no bridge row.
A positive and a negative problem can cancel each other out, so a zero is not proof. Run the checks below as well.
Checking the bridge itself
Most bad results start in the bridge. Test it directly with two measures.
Bridge Duplicate Rows =
COUNTROWS ( AccountBridge ) - COUNTROWS ( DISTINCT ( AccountBridge ) )DISTINCT on a table removes duplicate rows. The measure should return 0. If it does not, the bridge was not built from unique pairs, and the duplicates will multiply transaction amounts. Go back to the calculated table that creates AccountBridge and wrap it in DISTINCT.
Accounts Missing From Bridge =
COUNTROWS (
EXCEPT (
ALL ( Accounts[AccountID] ),
ALL ( AccountBridge[AccountID] )
)
)EXCEPT returns the account IDs that are in Accounts but have no row in the bridge. Transactions on those accounts disappear from every customer total. Whether that is a data problem or a business rule (some accounts have no customer) is a decision for the model owner. Make it a visible decision, and don't let it happen by accident.
Reading symptoms
| Symptom | Likely cause | First check |
|---|---|---|
| Customer total is larger than the grand total | Shared accounts (expected) | `Rows Check` above zero |
| One customer's amount is a multiple of the expected value | Duplicate bridge rows | `Bridge Duplicate Rows` |
| Customer totals are lower than the source | Accounts missing from the bridge | `Accounts Missing From Bridge` |
| Slicer on Customer does nothing to `Total Amount` | Bridge relationship is single direction and the measure has no `CROSSFILTER` | Relationship arrow in Model view |
| Blank row appears in a visual | Key values in a fact table with no match in the dimension | Compare key lists in Power Query |
| "Ambiguous path" error when you add a relationship | A second filter route exists between two tables | Inactive or removed relationship |
A validation workflow
Run the same checks every time the model changes. The order matters. Fix data problems before you tune anything.
The comparison step does not need a big sample. Pick one customer with a single account, one with several accounts, and one who shares an account. Calculate the expected amounts in the source system, using SQL or a spreadsheet pivot, and compare them to the report. Do not use the same model to check itself.
Watching performance
Bridge models add joins. A customer filter now travels through three tables, and CROSSFILTER or bidirectional filtering widens the set of rows the engine has to consider. The cost depends mostly on three things.
| Factor | Why it matters | What to do |
|---|---|---|
| Bridge size | Each filter pass scans or joins the bridge | Keep it to two integer key columns, with no descriptive text |
| Key data type | Text keys compress poorly and join slowly | Use integer surrogate keys where you can |
| Bidirectional relationships | Filters flow in more directions and can create ambiguity | Limit them to the bridge-to-dimension relationship and avoid them elsewhere |
| Iterators over large sets | `SUMX` runs the inner measure once per row | Do not run `Rows Check` on a high-cardinality visual |
| Native many-to-many | Relationships are weak, so the engine cannot use the same join shortcuts | Compare timings against the bridge version before choosing |
Hide the bridge table and its key columns from the report view. This is not a speed tweak. It stops report authors from dragging bridge columns into visuals and creating confusing filter paths.
Measuring instead of guessing
Use two tools:
- Performance Analyzer in Power BI Desktop. Start recording, refresh the visuals, and read the DAX query time for each visual. Copy the query for a slow visual.
- DAX Studio with Server Timings turned on. Paste the copied query and run it. The output splits time into the storage engine, which scans compressed data, and the formula engine, which evaluates DAX logic. A high formula-engine share often points to an iterator or a measure that is evaluated many times. A high storage-engine share points to scans and joins, which suggests relationship or key problems.
Test each alternative on the same visual with a cold cache. Compare Amount via Bridge (using CROSSFILTER) against this TREATAS version:
Amount for Selected Customers =
CALCULATE (
SUM ( Transactions[Amount] ),
TREATAS ( VALUES ( AccountBridge[AccountID] ), Transactions[AccountID] )
)TREATAS applies the visible bridge account IDs directly to Transactions[AccountID]. The results should match Amount via Bridge. If they do not, one of the two has a filter path problem, and you have found it before a user did. Run both and keep whichever is faster and clearer for your data volume.
Performance warning signs
Look out for these as the data grows:
- A visual that was fast with 10,000 bridge rows takes seconds with 10 million.
- Totals that take much longer than the rows above them, which suggests the total-row evaluation does extra work.
- Measures that use
CROSSFILTERinside an iterator.
If the bridge grows too large, reduce its grain. For example, bridge a coarser key such as a customer group rather than every account. Do that only if the business question allows it.
Exercise
A report has Customers on rows, and the grand total of Total Amount is 500. The customer rows add up to 620. Rows Check in an unfiltered card returns 120, and Bridge Duplicate Rows returns 0. What is the likely explanation, and what would a Rows Check value of -40 (with the same data) suggest instead?
Show answer
The bridge has no duplicates, and the gap of 120 equals the amount of transactions on accounts shared by several customers, which each customer row counts once. This is expected non-additive behavior, so decide whether to show customer totals without a grand total or to add allocation weights. A value of -40 would mean 40 of transaction amount is not reachable through the bridge, most likely because some accounts have no bridge row. Run Accounts Missing From Bridge to confirm.
Exercise
You compare Amount via Bridge and Amount for Selected Customers on the same visual, and both give the same numbers. Server Timings shows that one takes 40 ms and the other 900 ms, mostly in the formula engine. What should you do next, and why?
Show answer
Keep the faster measure if its results match the source on your test customers, and check why the slow one spends time in the formula engine. Common causes are an iterator around a measure that uses CROSSFILTER, or a visual that evaluates the measure for many rows. Equal numbers mean either measure is correct for this data, so choose on timing and clarity.