Sub topic 6
The bridge table pattern
This chapter explains what a bridge table is, what it contains, and why it solves the many-to-many problem. It assumes you can read Power BI Desktop's model view and know fact and dimension tables. It also assumes you understand one-to-many relationships and can write basic DAX measures with SUM and CALCULATE. The chapters on building the bridge and on wiring its filters come later. Here you learn the shape of the pattern and the reasons behind it.
The problem the pattern solves
A many-to-many relationship exists when each row on one side can match several rows on the other side, and the reverse is also true. A bank is a good example. One customer can hold several accounts. One joint account can belong to several customers.
Power BI's classic relationship engine expects at least one side of a relationship to hold unique values in the key column. Neither Customers nor Accounts can be that unique side for the other, because the link between them is a list of pairs, not a single value on each row. That list of pairs is the missing piece. A bridge table stores it explicitly.
What a bridge table is
A bridge table (also called a junction table, link table, or factless fact table) is a table whose rows are the valid pairings of two keys. It usually has no numeric measures of its own. Each row says "this account belongs to this customer."
Here is the source data for the bank example:
| AccountID | CustomerID |
|---|---|
| A1 | C1 |
| A1 | C2 |
| A2 | C1 |
| A3 | C2 |
| A3 | C3 |
Account A1 is a joint account for C1 and C2. Customer C1 holds A1 and A2. Every row is one pair, and no pair repeats.
The bridge turns one many-to-many relationship into two one-to-many relationships:
Customers(one) toAccountBridge(many), onCustomerID.Accounts(one) toAccountBridge(many), onAccountID.
Each dimension table holds each key once, so each dimension can be the unique side. The bridge repeats each key as often as needed, so it is the many side of both relationships. The model now uses only relationship types that Power BI has supported for years.
Where the bridge sits in the model
In a star schema, the fact table sits at the center and dimensions surround it. A bridge adds a second hop. In this example the fact table Transactions relates to Accounts. Customers has no direct link to Transactions. It reaches transactions through the bridge and then through Accounts.
The path from a customer to its amounts is:
CustomersAccountBridgeAccountsTransactions
A bridge usually sits between two dimensions. It can also sit between a dimension and a fact table, for example when a fact row can carry several tags. The structure is the same either way: two keys, one row per valid pair.
How filters travel through the bridge
This is the part that causes most confusion, so follow it step by step. A filter in Power BI moves from the one side of a relationship to the many side. That is the default single cross-filter direction.
Start with a slicer on Customers that selects C1.
- The filter moves from
CustomerstoAccountBridge, which is one-to-many in the filter's direction. The bridge keeps the rows (A1, C1) and (A2, C1). - The next hop is from
AccountBridgetoAccounts. That hop goes from the many side to the one side. By default the filter does not travel that way, soAccountsstill shows every account. Transactionsis filtered byAccounts, which is not filtered. A measure such asSUM ( Transactions[Amount] )returns the grand total for every customer.
The symptom is easy to spot. Every customer shows the same number. The bridge itself works, but the filter stops at it.
You have three ways to continue the filter from the bridge to Accounts:
- Set the relationship between
AccountBridgeandAccountsto filter in both directions. - Switch on bidirectional filtering for one measure only, using
CROSSFILTER. - Copy the visible
AccountIDvalues from the bridge ontoTransactionswithTREATAS.
Later chapters cover each option. Each has trade-offs in ambiguity, performance, and reuse across reports. For now, remember the rule behind them: a bridge relationship is one-to-many in both directions of travel away from the bridge, so the filter has to climb back up one of them.
The base measure
Every comparison in this tutorial uses one plain measure on the fact table:
Total Amount = SUM ( Transactions[Amount] )With the default single-direction relationships, put Customers[CustomerName] in a table visual next to Total Amount. Each row shows the same grand total, as described above. After you fix the filter flow, each customer row shows only that customer's accounts.
What the bridge must guarantee
The pattern only works if the bridge meets a few conditions.
- Unique pairs. Each
AccountIDandCustomerIDcombination should appear once. Duplicate pairs inflate amounts, because each duplicate row adds another path to the same transactions. - Unique keys on the dimensions.
Accounts[AccountID]andCustomers[CustomerID]must each contain a value once. A repeated key makes the relationship many-to-many again, and Power BI cannot create it as one-to-many. - Matching keys. Every key in the bridge should exist in its dimension. A bridge key with no matching dimension row appears under a blank row in the dimension visual.
- Same data types. The key columns on both sides of a relationship need the same data type. Text
"1"does not match number1.
Why not just use a native many-to-many relationship
Power BI Desktop lets you create a many-to-many cardinality relationship directly between two columns with no bridge. That feature is covered in its own chapter. The short comparison is below.
| Question | Bridge table | Native many-to-many |
|---|---|---|
| Extra table in the model | Yes | No |
| Pairs visible and editable as data | Yes | No, matching happens inside the engine |
| Place to store weights or dates per pair | Yes, as extra columns | No |
| Needs the pair list as a source | Yes | No, uses the columns as they are |
| Filter direction to manage | Two relationships | One relationship |
The bridge costs one more table and one more hop. In return the pairing is explicit data you can inspect, filter, test, and extend. A bridge also keeps you on one-to-many relationships, which are the best-understood relationship type in the engine.
Extending a bridge with extra columns
Because the bridge holds one row per pair, it can carry attributes of the pair. Examples include a Role column such as "Primary" or "Joint", a start date and end date for the link, or an allocation weight that says what share of an amount belongs to each customer. The allocation weight case matters because it can fix double counting. A later chapter covers it. For now, keep in mind that a bridge with only two key columns is the minimum, not the limit.
Common errors with the pattern
| Symptom | Likely cause |
|---|---|
| Every customer shows the same total | Filter does not climb from the bridge to `Accounts` because the direction is single |
| Cannot create a one-to-many relationship | Key column on the dimension side contains duplicates |
| A blank row appears in `Customers` or `Accounts` | The bridge has keys that the dimension does not contain |
| Customer totals add up to more than the grand total | Shared accounts are counted once per customer. This is expected, and the Totals and double counting chapter explains it |
| Amounts are higher than expected even for one customer | Duplicate pairs in the bridge |
The fourth row is not a bug in the model. It is what a many-to-many question means. If a joint account's amount is reported under both owners, the sum across owners counts it twice. Whether that is acceptable depends on the report's purpose.
Putting it together
The pattern has four parts, in order:
- Identify the many-to-many link between two dimensions.
- Store the valid pairs in a table with one row per pair.
- Relate each dimension to the bridge with a one-to-many relationship.
- Make filters travel through the bridge to the table that holds the fact rows.
Parts 2 and 3 are the structure covered here. Part 2's construction in Power Query or DAX comes in the next chapter, and part 4 comes after that.
Exercise
In the bank model, the bridge AccountBridge has a one-to-many relationship from Customers and another from Accounts, both with single cross-filter direction. Transactions relates to Accounts. A table visual shows Customers[CustomerName] and Total Amount, and every row shows the same number. Explain why, and name one option that fixes it.
Show answer
The filter from Customers moves down to AccountBridge because the bridge is the many side. It cannot move from the bridge up to Accounts, because that hop goes from the many side to the one side and the direction is single. Accounts and therefore Transactions stay unfiltered, so every customer shows the grand total. Fixes include setting the AccountBridge to Accounts relationship to filter in both directions, using CROSSFILTER inside the measure, or using TREATAS to apply the bridge's visible AccountID values to Transactions.
Exercise
A source table of account and customer pairs contains the row (A1, C1) twice. What happens if you load it as the bridge without removing the duplicate, and why do the two dimension relationships still get created?
Show answer
Both relationships are created because each dimension holds unique keys and the bridge is the many side, so repeated pairs do not break cardinality. The duplicate gives A1 two rows for C1, so when the filter passes through the bridge, the amounts for A1 can be counted more than once. Totals for C1 can come out too high without any warning, so duplicates must be removed when the bridge is built.