Sub topic 3
Cross-filter direction
This chapter assumes you can read Power BI Desktop's model view and know one-to-many relationships, fact and dimension tables, and basic DAX with SUM and CALCULATE. It covers the cross-filter direction setting: what it does, when to change it, and what goes wrong when you do.
What the setting controls
Every relationship has a cross-filter direction. It decides which way a filter travels between the two tables.
- Single: filters flow from the "one" side to the "many" side only. A selection on a dimension filters the fact table. A selection on the fact table does not filter the dimension.
- Both: filters flow in either direction.
For a standard star schema, single is the default and almost always the right choice. A slicer on Customers[Region] reduces Transactions, and the measures give the numbers you expect.
Why single direction is not enough for a bridge
In a bridge model, Customers sits on one side of AccountBridge, and Accounts and Transactions sit on the other. A filter on Customers has to cross the bridge to reach Transactions.
The path is Customers to AccountBridge to Accounts to Transactions. The first step goes from the "one" side to the "many" side, so it works. The step from AccountBridge to Accounts goes against the relationship. Accounts[AccountID] is the "one" side, and the bridge is the "many" side. With single direction, the filter stops at the bridge and Transactions is not filtered by the selected customer.
You can fix this in two ways:
- Set the
AccountBridgetoAccountsrelationship to Both in the model. - Leave the model on single direction and enable the reverse flow inside a measure.
Option 1: Set Both in the model
In model view, double-click the relationship between AccountBridge and Accounts. Set Cross-filter direction to Both. Every visual now sends filters across the bridge in both directions.
This is simple, but it applies to every measure and every visual. It can create ambiguous filter paths when other relationships connect the same tables. It can also slow queries, because the engine has to propagate filters in more places.
Option 2: Enable the flow per measure
CROSSFILTER changes the direction of an existing relationship for the duration of one CALCULATE. The model stays on single direction.
Total Amount = SUM ( Transactions[Amount] )Amount via Bridge =
CALCULATE (
SUM ( Transactions[Amount] ),
CROSSFILTER ( AccountBridge[AccountID], Accounts[AccountID], BOTH )
)Total Amount is the plain measure. It ignores the customer selection because the filter stops at the bridge. Amount via Bridge turns on bidirectional filtering for that one calculation, so a customer selection reaches Transactions.
Comparing the two options
| Aspect | Both in the model | CROSSFILTER in a measure |
|---|---|---|
| Scope | All visuals and measures | Only the measure that uses it |
| Risk of ambiguity | Higher | Lower |
| Maintenance | One setting | Must remember to use the measure |
| Visibility | Visible in model view | Hidden inside DAX |
A common error
A customer who shares an account with another customer makes the same transaction count for both. A total across customers can then exceed the real grand total. Changing the direction does not cause this, but it exposes it. A later chapter covers how to detect and handle it.
Exercise
A model has Customers → AccountBridge ← Accounts → Transactions, all on single direction. You select a customer in a slicer, and a card showing SUM ( Transactions[Amount] ) does not change. Why, and what are two ways to fix it?
Show answer
The filter travels from Customers to AccountBridge, but the step from AccountBridge to Accounts goes from the many side to the one side, so single direction blocks it. Transactions is never filtered. Fix it by setting the AccountBridge to Accounts relationship to Both, or by wrapping the measure in CALCULATE with CROSSFILTER ( AccountBridge[AccountID], Accounts[AccountID], BOTH ).