Sub topic 7
Cross-filter direction: single and both
This chapter explains the cross-filter direction setting on a relationship. It covers what single and both mean, how each one changes the numbers in a visual, and how to set the direction in the model or only inside one measure.
Prerequisites
This chapter assumes you can do the following:
- Open the Model view in Power BI Desktop.
- Read a one-to-many relationship, with the "one" side on a dimension table and the "many" side on a fact table.
- Write a simple measure such as a sum of a column.
What cross-filter direction means
Every relationship has a cross-filter direction. It sets which table can filter the other through the relationship.
- Single: filters flow from the "one" side to the "many" side only. A selection on a dimension table filters the fact table. A selection on the fact table does not filter the dimension table.
- Both: filters flow in each direction. A selection on the fact table can also narrow the dimension table.
In the Model view, a single-direction relationship shows one arrowhead on the line. It points from the dimension table toward the fact table. A both-direction relationship shows two arrowheads.
The default for a new one-to-many relationship is single, from the "one" side to the "many" side. Keep it unless you have a specific reason to change it.
A worked scenario
Suppose the model has three tables:
Customer(dimension), with one row per customer.Product(dimension), with one row per product.Sales(fact), with one row per order line. It holdsCustomerKey,ProductKey, andSalesAmount.
Both relationships are one-to-many with single direction. Each arrow points from the dimension to Sales.
Now put a Product[Category] slicer on the page and a table visual listing Customer[CustomerName]. What happens depends on the direction.
With single direction:
- The slicer filters
Product. ProductfiltersSales, soSaleskeeps only rows for the chosen category.- The filter stops there. It does not continue from
SalestoCustomer. - The table visual still lists every customer, because nothing filtered
Customer.
Each customer's Total Sales is correct for the chosen category. Customers who bought nothing in that category show a blank total, but their names still appear unless the visual hides rows with blank values.
With the Sales-to-Customer relationship set to both:
- The slicer filters
Product, which filtersSales. Salesnow also filtersCustomer.- Only customers with at least one matching sales row remain.
That second result is why people reach for both-direction filtering. The arrows show it:
Setting the direction
You can set the direction in the Edit relationship dialog. Open it by double-clicking the relationship line in the Model view, or through Manage relationships on the Home tab.
- Open the Edit relationship dialog.
- Find the Cross-filter direction list.
- Choose Single or Both.
- Select OK and check your visuals.
Some combinations are limited by cardinality. A one-to-one relationship always filters in both directions. A many-to-many relationship lets you pick either direction.
Changing direction for one measure only
A model-wide change affects every visual that uses the relationship. DAX offers a narrower option. The CROSSFILTER function sets the direction for the duration of a single CALCULATE, and the model setting stays as it was.
Customers Who Bought =
CALCULATE (
DISTINCTCOUNT ( Customer[CustomerKey] ),
CROSSFILTER ( Sales[CustomerKey], Customer[CustomerKey], Both )
)With this measure, a Product[Category] slicer narrows the customer count to customers who bought in that category. Other measures keep the single-direction behavior.
CROSSFILTER accepts three direction values:
| Value | Effect |
|---|---|
| `Both` | Filters flow in both directions for this calculation. |
| `OneWay` | Filters flow from the "one" side to the "many" side only. |
| `None` | The relationship is ignored for this calculation. |
The two columns you pass must be the two ends of an existing relationship. CROSSFILTER does not create relationships.
Why both is risky
Both-direction filtering looks convenient, but it has costs. Treat it as an exception.
Unexpected results
A both-direction relationship lets a selection travel further than you expect. One slicer can reach tables you did not intend, and a measure that was correct can start returning different values. These bugs are hard to spot because nothing throws an error.
Ambiguous paths
If two tables are connected by more than one route, Power BI cannot tell which route a filter should use. Both-direction relationships create such routes easily. Power BI may deactivate a relationship or refuse to let you set the direction. The next chapters cover ambiguity in detail.
Slower queries
When a filter travels in both directions, the engine must evaluate more tables for each visual. On large models this can slow visuals noticeably.
Row-level security surprises
In a model that uses row-level security, both-direction filtering can let a security filter on one table affect others, which can change what users see. Test security roles after any direction change.
Safer alternatives
Before you set a relationship to both, consider these options:
- Filter on the visual. For the customer example, add
Total Salesto the visual and apply a "is not blank" filter to it. This hides customers with no sales for the selected category and needs no model change. - Use a measure with
CROSSFILTER. The change applies only where you need it. - Use a slicer on the fact-side data. If the slicer's column can live on a dimension, move it there so the normal single-direction flow does the work.
Choosing a direction
| Situation | Recommended setting |
|---|---|
| Standard dimension-to-fact relationship | Single |
| A slicer must be limited to values that have data | Visual filter or a `CROSSFILTER` measure |
| One-to-one relationship | Both (the only behavior available) |
| Many-to-many relationship through a bridge table | Usually single toward the fact table, with care |
Common mistakes
- Expecting a dimension to shrink when the fact table is filtered. With single direction it will not. Use one of the alternatives above.
- Reading the arrow backwards. The arrow points in the direction filters flow. In a standard star schema it points toward the fact table.
- Setting both and then adding a second route between tables. This is a common cause of ambiguity.
- Forgetting to retest. After a direction change, recheck any measure that touches the relationship.
Exercise
A model has a one-to-many relationship from Product to Sales, set to single direction. A visual lists Product[ProductName]. A slicer on Sales[Region] is set to "West". The visual still lists every product. Why, and how could you limit the list to products sold in the West?
Show answer
Region lives on the fact table, and with single direction a filter on Sales does not flow back to Product, so the Product table is not filtered. Options are to add Total Sales to the visual and filter it to "is not blank", to use a measure that applies CROSSFILTER with Both on the Sales[ProductKey] to Product[ProductKey] relationship, or to set the relationship to both, accepting the risks.
Exercise
Which CROSSFILTER direction value ignores a relationship for the duration of a calculation?
Show answer
None.