Sub topic 7
Cross-filter direction: single and both
This chapter assumes you can create a relationship in the Model view, know that a one-to-many relationship has a "one" side and a "many" side, and can write a simple measure such as a sum. It covers the cross-filter direction setting and when to change it.
What cross-filter direction controls
Cross-filter direction decides which way a filter travels across a relationship. In a typical star schema, a dimension table such as Customer sits on the "one" side. A fact table such as Sales sits on the "many" side.
There are two settings:
- Single: filters flow from the "one" side to the "many" side. A slicer on
ProductfiltersSales, but a filter onSalesdoes not filterProduct. - Both: filters flow in either direction across the relationship.
Single is the default for one-to-many relationships. It is also the safest choice. You set it in the Model view by double-clicking the relationship line, or in the Manage relationships dialog. The option is called "Cross-filter direction".
Seeing the difference
Suppose a slicer on Product[Category] is set to "Bikes". You want to know how many customers bought a bike.
With single direction, the filter reaches Sales from Product. It stops there, because Sales filters Customer only if the relationship is set to both. A distinct count over Customer[CustomerKey] therefore returns every customer.
You can turn on both directions for one measure only, without changing the model:
Customers Who Bought =
CALCULATE (
DISTINCTCOUNT ( Customer[CustomerKey] ),
CROSSFILTER ( Sales[CustomerKey], Customer[CustomerKey], Both )
)CROSSFILTER changes the direction only while this measure evaluates. The model's relationship stays single, so other measures behave as before.
Setting both in the model
You can also set the relationship itself to both. Every measure and visual then sees the two-way filtering. This is convenient, but it carries costs:
| Concern | What can happen |
|---|---|
| Performance | Filters spread to more tables, so queries do more work. |
| Ambiguity | Two-way relationships can create several paths between tables. Power BI may refuse or deactivate one. |
| Surprising results | Slicers start filtering each other, and totals change in ways that are hard to trace. |
A practical rule
- Keep every relationship single by default.
- If one measure needs the reverse direction, use
CROSSFILTERinside that measure. - Change the model setting to both only when many visuals need it, and test the totals afterward.
Exercise
A Product slicer is set to "Bikes", but a card showing DISTINCTCOUNT ( Customer[CustomerKey] ) still shows all customers. The Sales-to-Customer relationship uses single direction. Give two ways to fix it and say which is safer.
Show answer
Either set the relationship's cross-filter direction to Both, or wrap the measure in CALCULATE with CROSSFILTER ( Sales[CustomerKey], Customer[CustomerKey], Both ). The CROSSFILTER version is safer because it affects only that measure and leaves the model's filtering unchanged for every other visual.