Sub topic 7
Building the bridge table
This chapter assumes you can work in Power BI Desktop model view, know the terms fact table and dimension table, and can write basic DAX with SUM and CALCULATE. It builds on the previous chapter, which explained why a bridge table helps when accounts and customers relate many-to-many.
What the bridge must contain
A bridge table holds one row for each valid pairing of two keys. In this example, each row says "this customer is linked to this account". The bridge needs two properties to work well:
- It has only the two key columns,
AccountIDandCustomerID. - Each pair appears once. A pair that appears twice can inflate sums when filters pass through the bridge.
Your data often does not meet the second property. A source table named AccountCustomer may come from an operational system that logs a row for each event, such as each time a customer was linked to an account. The same pair can then appear many times.
Build it with a calculated table
A calculated table is a table defined by a DAX expression. Power BI evaluates it when the model refreshes. Create one from the Modeling tab with New table:
AccountBridge =
DISTINCT (
SELECTCOLUMNS (
AccountCustomer,
"AccountID", AccountCustomer[AccountID],
"CustomerID", AccountCustomer[CustomerID]
)
)SELECTCOLUMNS returns a table with only the two columns you name, and it renames them as it goes. DISTINCT then removes repeated rows from that result. Because the table keeps only these two columns, it removes duplicate pairs, not duplicate values within one column.
You can do the same work in Power Query by selecting the two columns, choosing Remove Rows, then Remove Duplicates. Choose Power Query when you want the bridge built before it loads into the model. Choose the calculated table when you want to keep AccountCustomer as it is and derive the bridge from it in the model.
Check the keys
Before you create relationships, confirm the table does what you expect. Two checks catch most problems:
- Compare row counts.
COUNTROWS ( AccountBridge )should be less than or equal toCOUNTROWS ( AccountCustomer ). It should equal the number of distinct pairs. - Look for orphan keys. These are bridge values that do not exist in the dimension tables. An
AccountIDin the bridge with no match inAccountswill not filter anything, and the rows silently drop out of results.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Power BI warns about a many-to-many relationship when you connect the bridge | Bridge still contains duplicate pairs, or a dimension key is not unique | Rebuild the bridge with `DISTINCT`, and confirm `Accounts[AccountID]` and `Customers[CustomerID]` are unique |
| Bridge has more columns than expected | `AccountCustomer` was used directly, with date or status columns | Select only the two key columns first |
| Some accounts have no customers in visuals | Blank or mismatched keys, such as different text casing or trailing spaces | Clean the keys in Power Query so both sides match |
| Calculated table is empty | Wrong source table name, or the source did not load | Check the table name in the formula and refresh |
Where this leads
At this point the bridge exists, but it is not connected. The next chapter connects AccountBridge to Accounts and Customers. That chapter also sets filter direction, which decides whether a Customer selection reaches the transaction data.
Exercise
AccountCustomer has 1,000 rows, but only 640 distinct AccountID and CustomerID pairs. After you build AccountBridge with the DISTINCT ( SELECTCOLUMNS ( ... ) ) formula, how many rows should it have, and why should you not build the bridge from AccountID alone?
Show answer
It should have 640 rows, one for each distinct pair. AccountID alone loses which customers share each account, so it cannot connect accounts to customers.