Sub topic 8
Wiring the bridge: relationships and filter direction
This chapter assumes you can work in Power BI Desktop model view and know what a fact table and a dimension table are. It also assumes you know one-to-many relationships and can write basic DAX with SUM and CALCULATE. You should already have a bridge table of unique key pairs, as built in the previous chapter. Here you connect that bridge to the model and decide which way filters flow through it.
The model we are wiring
The examples use four tables.
| Table | Role | Key columns |
|---|---|---|
| `Customers` | Dimension | `CustomerID` (unique) |
| `Accounts` | Dimension | `AccountID` (unique) |
| `AccountBridge` | Bridge | `CustomerID`, `AccountID` (unique pairs) |
| `Transactions` | Fact | `AccountID`, `Amount` |
A customer can hold many accounts, and an account can be shared by many customers, such as a joint account. Each transaction belongs to exactly one account. The bridge stores one row for each customer and account pair that exists.
Step 1: Create the two one-to-many relationships
The bridge sits between the two dimensions. Each dimension has a unique key, so each connects to the bridge as the "one" side:
Customers[CustomerID]toAccountBridge[CustomerID], one-to-many, single direction.Accounts[AccountID]toAccountBridge[AccountID], one-to-many.
You also need the existing relationship from Accounts[AccountID] to Transactions[AccountID], one-to-many, single direction. Transactions connect to the account, not the customer, because the account is what a transaction belongs to.
Both bridge relationships are ordinary one-to-many relationships. Neither needs the native many-to-many cardinality option. The bridge turns one many-to-many relationship into two one-to-many relationships, and that is why this pattern is predictable.
Step 2: Follow the filter
A filter in a Power BI model travels from the "one" side to the "many" side of a relationship. This is the default single direction. Trace a selection of one customer through the model:
- The customer slicer filters
Customersto one row. CustomersfiltersAccountBridge, because the bridge is the many side. The bridge now shows only that customer's account pairs.- The bridge should now filter
Accounts. ButAccountsis the "one" side of that relationship, so the default direction does not allow it.
The filter stops at the bridge. Accounts and Transactions still show everything, so the visual shows the grand total for every customer.
This is the central wiring problem. The bridge relationship to Accounts has to carry a filter from the many side back to the one side. You have three ways to do that.
Option A: Set the relationship to both directions
Open the relationship between AccountBridge[AccountID] and Accounts[AccountID]. Set Cross filter direction to Both. Filters now flow from the bridge into Accounts, and then from Accounts into Transactions through the existing single-direction relationship.
With this setup, plain measures work with no special DAX:
Total Amount = SUM ( Transactions[Amount] )Place Customers[CustomerName] on rows and [Total Amount] as the value. Each customer now sees only the transactions on their own accounts.
The cost is that the setting applies to the whole model, for every query and every visual. Bidirectional relationships bring several risks:
- Ambiguity. If a second path connects the same two tables, Power BI cannot choose between them. It deactivates one relationship or reports an ambiguous path. Keep exactly one filter path between any two tables.
- Slower queries. The engine must evaluate filters in more places. Large dimensions make this noticeable.
- Unexpected filtering of slicers. A slicer on one dimension can start limiting the values shown in another slicer, because the filter now travels in both directions.
- Row-level security. A security filter on a table only travels in a direction where the relationship is set to apply security filters in both directions. Check this setting deliberately before you rely on it.
Option B: Keep the model single-direction and use CROSSFILTER
Leave the bridge relationship to Accounts in single direction. Then turn on bidirectional filtering only inside the measures that need it:
Amount via Bridge =
CALCULATE (
SUM ( Transactions[Amount] ),
CROSSFILTER ( AccountBridge[AccountID], Accounts[AccountID], BOTH )
)CROSSFILTER changes the direction of an existing relationship for the duration of one CALCULATE. It takes the two columns that define the relationship and a direction. Outside this measure, the model behaves as a standard single-direction schema.
This keeps the model safe by default. Visuals that do not need the bridge, such as a plain account list, are not affected. The trade-off is that every measure that crosses the bridge must include the CROSSFILTER call. If you forget it in one measure, that measure returns the unfiltered total.
Option C: Use TREATAS and drop the filter into the fact table
A third approach does not depend on the bridge-to-Accounts direction at all. The measure reads the account IDs that survive in the bridge, and applies them directly to the fact table:
Amount for Selected Customers =
CALCULATE (
SUM ( Transactions[Amount] ),
TREATAS ( VALUES ( AccountBridge[AccountID] ), Transactions[AccountID] )
)VALUES ( AccountBridge[AccountID] ) returns the account IDs that the customer selection has left visible in the bridge. TREATAS then applies those values as a filter on Transactions[AccountID], as if a relationship existed between those columns. The filter reaches Transactions directly. It does not pass through Accounts.
Because of that, this measure does not filter the Accounts table. A visual that shows account names next to this measure shows every account, with blank or zero values for the ones the customer does not hold. If you need Accounts to reflect the customer selection, use Option A or B.
Comparing the options
| Question | Both in model | CROSSFILTER | TREATAS |
|---|---|---|---|
| Where is the direction set? | Relationship property | Inside each measure | No relationship needed |
| Works with plain `SUM` measures? | Yes | No, needs the wrapper | No, needs the wrapper |
| Filters the `Accounts` table? | Yes | Yes | No |
| Risk of ambiguous paths | Higher | Lower | None |
| Effect on other visuals | Global | Only the measure | Only the measure |
For a small model with one bridge and one fact table, Option A is simple and often fine. For a larger model with several fact tables, Option B or C usually keeps the rest of the schema predictable.
Check the result: totals can double count
Wiring correctly does not mean the totals are right. When an account is shared by two customers, its transactions appear under both customers. Each row is correct. The sum of the rows is larger than the real grand total, because the shared transactions are counted once per customer.
Power BI does not warn you about this. The Rows Check measure from the validation set exposes it:
Rows Check =
VAR GrandTotal = CALCULATE ( [Total Amount], ALL ( Customers ) )
VAR VisibleSum = SUMX ( VALUES ( Customers[CustomerID] ), [Amount via Bridge] )
RETURN VisibleSum - GrandTotalA result of zero means each account belongs to one customer, so nothing is counted twice. A positive number is the amount counted more than once. The next chapter covers how to handle this in report totals.
Common wiring errors
- Bridge keys not unique. If
AccountBridgecontains duplicate pairs, the totals inflate even though the relationships look correct. Build the bridge withDISTINCT, as shown in the previous chapter. - Wrong key on the "one" side.
Accounts[AccountID]must contain unique values. Duplicate account IDs force Power BI to set a many-to-many cardinality, which defeats the purpose of the bridge. - Filter stops at the bridge. Everything shows the same total for every customer. The bridge-to-
Accountsdirection is single and the measure has noCROSSFILTERorTREATAS. - Both directions plus a second path. A direct relationship from
CustomerstoTransactionscreates a second route to the fact table. Remove it or keep it inactive. - Mixing options. A model set to Both that also uses
CROSSFILTER ... BOTHin measures works, but it hides which mechanism actually applies. Pick one approach per relationship.
Exercise
A model has Customers, AccountBridge, Accounts and Transactions, with single-direction one-to-many relationships from each dimension to the bridge and from Accounts to Transactions. A table visual shows each customer next to [Total Amount] defined as SUM ( Transactions[Amount] ), and every customer shows the same grand total. Why does this happen, and name two ways to fix it without changing the bridge data.
Show answer
The filter from Customers reaches AccountBridge, but the relationship between AccountBridge and Accounts runs from Accounts (one) to the bridge (many). The customer filter cannot travel back to Accounts, so Transactions is never filtered. Fix 1: set the AccountBridge to Accounts relationship to cross-filter direction Both. Fix 2: keep the model single-direction and write the measure with CALCULATE and CROSSFILTER ( AccountBridge[AccountID], Accounts[AccountID], BOTH ), or with TREATAS ( VALUES ( AccountBridge[AccountID] ), Transactions[AccountID] ).