Sub topic 9
When to use both-direction filtering, and its risks
This chapter assumes you can create relationships in the Model view, you know that a one-to-many relationship has a "one" side (a dimension) and a "many" side (a fact table), and you know that the default cross-filter direction is single. If any of these is unfamiliar, review the earlier chapters on relationships, cardinality, and filter direction first.
What both-direction filtering does
A relationship has a cross-filter direction. With Single, a filter flows from the "one" side to the "many" side. A slicer on Product narrows the Sales rows. A slicer on Sales cannot narrow Product.
With Both, a filter also flows from the "many" side back to the "one" side. Power BI shows this in the Model view as arrows on both ends of the relationship line. You set it in the Edit relationship dialog, in the Cross-filter direction list.
This sounds harmless, but it changes how every visual and every measure that touches the two tables behaves. Each both-direction relationship adds a second route through which filters can travel, and the model gets harder to predict as the routes accumulate.
The problem it solves
The most common reason to use Both is a slicer that lists values from a dimension, where you want the list to shrink according to a selection made on another dimension.
Suppose the model has Customer, Product, and Sales. Both dimensions filter Sales. A report has a Customer slicer and a Product slicer. A user picks the Product category "Bikes". With single direction, the Customer slicer still lists every customer, including people who never bought a bike. The Product filter reaches Sales, but it stops there. It never travels from Sales back to Customer.
With Both on the Sales-to-Customer relationship, the filter continues. Sales is filtered to bike rows, and those rows filter Customer to the people who bought bikes. The Customer slicer now lists only those customers.
The same effect applies to a visual. A table of customer names with a Product filter applied will show only customers with matching sales.
Prefer the measure-level alternative
Changing the relationship affects the whole model. You can get the same behavior for one measure by using CROSSFILTER inside CALCULATE. The model keeps its single-direction relationship, and only this measure uses both directions:
Customers Who Bought =
CALCULATE (
DISTINCTCOUNT ( Customer[CustomerKey] ),
CROSSFILTER ( Sales[CustomerKey], Customer[CustomerKey], Both )
)A Product slicer now narrows this count to the customers who bought the selected products. No other measure changes. This is the safer default whenever the need is one number rather than the behavior of a slicer list.
The measure approach has limits. It does not change what a slicer lists, because a slicer is not a measure. If you need the slicer list itself to shrink, you need a both-direction relationship, or a different technique such as a visual-level filter on the slicer.
A third option for slicers is to filter the slicer visual with a measure. Add a measure that returns a value only when sales exist, such as Total Sales, to the slicer's visual-level filter with the condition "is not blank". The slicer then hides customers with no sales for the current selection, and the model stays single-direction.
Risks
Ambiguous paths
Power BI allows only one active filter path between two tables. When you set a relationship to Both, you can create a second path between two tables through a different route. Power BI then warns that the change creates ambiguity, or it turns the relationship inactive, and the Edit relationship dialog may refuse the setting. Ambiguity is covered in the next chapter. The practical point here is that Both makes it easy to reach that state, especially in models with several fact tables that share dimensions.
Unexpected results from filters flowing the wrong way
When a filter travels back to a dimension, that dimension then filters every other table related to it. A selection on one table can reach tables you did not intend to involve.
Example: Customer relates to Sales and also to a Returns fact table. If Sales-to-Customer is Both, a Product selection narrows Sales, which narrows Customer, which then narrows Returns. A measure on Returns now responds to a Product slicer even though Product has no relationship with Returns. The number may be correct for the question "returns by customers who bought this product", but a reader will probably interpret it as "returns of this product". Nothing in the visual shows the difference.
Slower queries
Both-direction filtering makes the engine do additional work, since filters must be pushed backward through the relationship. On large fact tables, the cost is a slower visual. The effect varies with the model, so measure it with Performance analyzer rather than assuming it.
Unclear totals
With both-direction relationships, totals and subtotals can differ from what the rows seem to add up to, because each row's filter context reaches more tables than it appears to. If a total looks wrong, check for Both relationships early in your diagnosis.
Guidelines for deciding
| Situation | Recommended approach |
|---|---|
| One measure needs to count dimension members that have related facts | CROSSFILTER in the measure |
| A slicer list should hide members without matching facts | Visual-level "is not blank" filter on a measure, or Both on that relationship |
| A fact table has no dimension that suits the question | Reshape the model, for example with a bridge table |
| Many-to-many between two dimensions | Bridge table with single-direction relationships, covered in a later chapter |
| Model has several fact tables sharing dimensions | Keep Both off the shared dimensions |
If you do choose Both, follow these rules:
- Apply it to one relationship at a time and test the report after each change.
- Prefer relationships between a dimension and a single fact table. Avoid Both on dimensions that are shared by several fact tables.
- Document it. A note in the model, or a comment in the measure descriptions, tells the next person why the arrows point both ways.
- Re-check totals on every page that uses the affected tables.
Worked check
To confirm the effect for yourself, build a small test:
- Place a Customer slicer and a Product slicer on a page, with the relationship Sales-to-Customer set to Single.
- Select one product category and note how many customers the Customer slicer lists.
- Open Edit relationship for Sales-to-Customer and change the Cross-filter direction to Both.
- Return to the page and select the same category. The Customer slicer should now list fewer customers.
- Change the setting back to Single if you prefer the measure-based approach, and add the
Customers Who Boughtmeasure to a card visual. Select the category again and check that the card shows the narrowed count.
Exercise
A report has a Product slicer and a card showing the number of customers. The card must show only customers who bought the selected products. The team does not want to change how any other measure behaves. Which approach fits, and why?
Show answer
Use a measure with CALCULATE and CROSSFILTER set to Both on the Sales-to-Customer relationship, such as DISTINCTCOUNT of Customer[CustomerKey]. The change applies only to that measure, so the model's single-direction relationship and every other measure keep their current behavior.
Exercise
Sales-to-Customer is set to Both. Customer also relates to a Returns table. A user selects a Product category. Why might the Returns total change, even though Product has no relationship with Returns?
Show answer
The Product filter narrows Sales. Because the relationship is Both, Sales then narrows Customer. Customer filters Returns through its own relationship, so the Returns total reflects only customers who bought that category.