Sub topic 16
Resolving many-to-many with a bridge table
This chapter assumes you can create one-to-many relationships, set cross-filter direction, and write a basic measure. It builds on the earlier chapters on many-to-many cardinality and filter propagation.
Why a bridge table
Power BI can create a direct many-to-many relationship, but it hides the real structure of the data. A bridge table (also called a junction table) makes that structure explicit. It holds one row for each valid pairing of two keys. Both original tables then relate to the bridge with ordinary one-to-many relationships.
Take a bank model. A joint account has several customers, and a customer can hold several accounts. Transactions is the fact table and records an AccountKey and an Amount. Account and Customer are dimensions. The bridge AccountCustomer has the columns AccountKey and CustomerKey.
Building the relationships
- Load or create the bridge table with distinct key pairs. In Power Query, select the two key columns and use Remove Duplicates.
- Make sure
Customer[CustomerKey]andAccount[AccountKey]are unique. They are the "one" sides. - Relate
Customer[CustomerKey]toAccountCustomer[CustomerKey], one-to-many, single direction. - Relate
Account[AccountKey]toAccountCustomer[AccountKey], one-to-many, single direction. - Relate
Account[AccountKey]toTransactions[AccountKey], one-to-many, single direction.
The filter direction problem
Filters flow from the "one" side to the "many" side. A customer slicer filters AccountCustomer. The bridge is on the "many" side of its relationship with Account, so the filter stops there. Account and Transactions never see the selection.
You have two options. You can set the Account–AccountCustomer relationship to both directions. That changes the whole model and can create ambiguous paths. Or you can enable both directions only inside the measure that needs it:
Total Amount = SUM ( Transactions[Amount] )
Amount by Customer =
CALCULATE (
[Total Amount],
CROSSFILTER ( AccountCustomer[AccountKey], Account[AccountKey], Both )
)The model keeps its safe single-direction relationships. Only this measure lets the filter travel from the bridge up to Account and then down to Transactions.
Common errors
- Duplicate pairs in the bridge. Duplicates are harmless for filtering but can inflate counts. Remove them.
- Bridge keys with no match in a dimension. The visuals then show a blank row. Check the keys against both dimensions.
- Setting the bridge relationships to both directions everywhere. This invites ambiguous paths, especially when other tables also connect to
Account.
Exercise
A customer slicer is set to one customer, but a card showing SUM(Transactions[Amount]) still shows the total for all accounts. All relationships are single direction. Why does the filter not reach Transactions, and how can you fix it for one measure only?
Show answer
The slicer filters Customer, which filters AccountCustomer. The bridge is on the "many" side of its relationship with Account, so the filter does not continue to Account or Transactions. Wrap the measure in CALCULATE with CROSSFILTER ( AccountCustomer[AccountKey], Account[AccountKey], Both ). This enables both directions for that measure only.