Sub topic 2
How Filters Flow Through Relationships
This chapter assumes you can write basic DAX measures and calculated columns. It also assumes you know a star schema: fact tables on the many side, dimension tables on the one side, and one-to-many relationships between them. You should also know how slicers, rows and columns of a report filter a measure.
By the end you will be able to predict which tables a filter reaches, which tables it does not, and why a measure sometimes ignores a selection you expected it to respect.
The model used in this chapter
The examples use a small star schema.
Salesis a fact table withAmount,Quantity,ProductKey,CustomerKey,OrderDateandShipDate.'Product'is a dimension table withProductKey,ColorandCategory.Customeris a dimension table withCustomerKeyandCountry.'Date'is a dimension table withDateandYear.
Each dimension has a one-to-many relationship to Sales. The "one" side is the dimension and the "many" side is Sales. The relationship between Sales[OrderDate] and 'Date'[Date] is active. The one between Sales[ShipDate] and 'Date'[Date] is inactive. A table can have only one active relationship to another table, so the second is kept inactive.
The base measure for the chapter is:
Total Sales = SUM ( Sales[Amount] )Filter context is a set of column filters
The previous chapter described filter context as the set of filters in effect when an expression is evaluated. Each filter is a restriction on the values of one or more columns. A slicer on 'Product'[Color] with "Red" selected adds a filter on that column. A row in a matrix labeled "2024" adds a filter on 'Date'[Year].
A filter on a column is applied to the table that holds that column. After the filter is applied, 'Product' contains only red products. That alone does not change Sales. Relationships are what carry the effect over to other tables.
Filters follow relationships in one direction by default
A relationship has a filter direction. In the common case, called a single-direction relationship, a filter on the "one" side propagates to the "many" side. A filter on the "many" side does not propagate back to the "one" side.
In a star schema this means the following.
- A filter on
'Product'[Color]filtersSales, because'Product'is on the one side. - A filter on
Customer[Country]filtersSalesin the same way. - A filter on
Sales[Quantity]does not filter'Product'orCustomer.
The process works like this. DAX first applies the filter to the table that owns the column. It then looks at each relationship from that table where the table is on the one side. For each such relationship, the related many-side rows are kept only if their key matches a surviving row on the one side. The result is a filtered Sales table, and SUM ( Sales[Amount] ) aggregates only the surviving rows.
A worked example
Consider a matrix with 'Product'[Category] on rows and Total Sales as the value, plus a slicer on Customer[Country] set to "France".
For the row "Bikes", the filter context contains two filters:
'Product'[Category] = "Bikes"Customer[Country] = "France"
Both filters reach Sales through their relationships. A Sales row survives only if its product is a bike and its customer is in France. The measure then sums Amount over those rows.
Neither filter conflicts with the other. They are on different columns of different tables, so they combine as an intersection (a logical AND). This is the normal case and it is why dimension filters stack naturally in a report.
What happens in the other direction
Now consider a measure evaluated while a filter sits on Sales:
Products Count = COUNTROWS ( 'Product' )Suppose a visual filters Sales[Quantity] to values above 2. The Sales table is reduced, but 'Product' is not affected, because the filter would have to travel from the many side to the one side. Products Count still returns the total number of products.
This is a frequent source of surprise. A filter on a fact table column does not reduce the dimension tables. If you need a measure to count only products that have matching sales, you have to express that explicitly, for example by counting rows in 'Product' that have related Sales rows:
Products With Sales =
COUNTROWS (
FILTER ( 'Product', NOT ISEMPTY ( RELATEDTABLE ( Sales ) ) )
)RELATEDTABLE returns the Sales rows related to the current product row, and those rows respect the filter on Sales. ISEMPTY tests whether any remain. The iteration over 'Product' creates a row context, which the next chapter covers. For now, notice that you reached the dimension by writing it explicitly instead of relying on automatic propagation.
Bidirectional filtering
A relationship can be set to filter in both directions. Power BI calls this cross-filter direction "Both". With it, a filter on Sales also propagates to the dimension on the other end.
With a bidirectional relationship between 'Product' and Sales, the Products Count measure above would shrink when Sales[Quantity] is filtered.
This can look like a convenient fix, but it has costs.
- It can create ambiguity. If several paths connect two tables, DAX has to choose one, and the model may refuse to activate the relationship.
- It can slow queries, because filters travel further and more tables are touched.
- It can change the results of existing measures in ways that are hard to trace.
A common recommendation is to keep relationships single-direction by default and to enable bidirectional filtering for a single measure, using the CROSSFILTER function inside CALCULATE:
Products Count Bidirectional =
CALCULATE (
COUNTROWS ( 'Product' ),
CROSSFILTER ( Sales[ProductKey], 'Product'[ProductKey], BOTH )
)The change applies only while that CALCULATE evaluates. The model itself stays unchanged.
Filtering through more than one hop
Filters can travel across several relationships in sequence. Suppose the model also has a Subcategory table on the one side of a relationship with 'Product', which in turn is on the one side of a relationship with Sales. A filter on Subcategory propagates to 'Product', then to Sales. Each hop must go from the one side to the many side for the filter to continue under single-direction rules.
This is why snowflake schemas still work with plain measures. The filter takes a longer path, but the direction rule is the same at every step.
Role-playing dimensions and inactive relationships
The 'Date' table has two possible links to Sales: through OrderDate and through ShipDate. Only one can be active. When a matrix puts 'Date'[Year] on rows, the filter travels through the active relationship, so the values are grouped by order date.
The inactive relationship does not propagate filters at all unless a measure turns it on. A later chapter shows how USERELATIONSHIP does this inside CALCULATE. For now, remember that an inactive relationship exists in the model but plays no part in filter propagation.
Relationships and blank rows
If a Sales row has a ProductKey with no match in 'Product', DAX handles it by adding a blank row to 'Product'. These unmatched sales appear under a blank category in a report. A filter on a 'Product' column that selects all values includes this blank row, so unmatched sales are still counted. A filter that selects specific values excludes it.
This explains why a report total can be larger than the sum of the visible rows. The missing amount sits under the blank member. Fixing the data, or checking the key columns, is the right remedy. Hiding the blank in the report only conceals the gap.
Checking what a filter reaches
When a result looks wrong, test propagation directly. These measures show which tables are affected by the current filter context:
Selected Colors = COUNTROWS ( VALUES ( 'Product'[Color] ) )
Rows In Sales = COUNTROWS ( Sales )
Rows In Product = COUNTROWS ( 'Product' )Place them in a table visual next to the field you are filtering with. If Rows In Sales drops and Rows In Product does not, you are filtering from the fact side and the filter is not reaching the dimension. If neither changes, the filter is not reaching the table at all, which often means the relationship is inactive, missing, or based on the wrong column.
Common mistakes in this area
| Symptom | Likely cause | What to check |
|---|---|---|
| A slicer on a dimension has no effect on a measure | The tables are not related, or the relationship is inactive | Model view: is there an active relationship between them? |
| A dimension count does not shrink when a fact column is filtered | The filter goes against the relationship direction | Direction of the relationship |
| Totals exceed the sum of visible rows | Fact rows with no matching dimension row | Blank member in the dimension |
| Results change after enabling bidirectional filtering | Filters now travel both ways, or paths became ambiguous | Use `CROSSFILTER` on specific measures instead |
| A date slicer groups by the wrong date | The active relationship uses a different date column | Which relationship is active |
What this means for CALCULATE
CALCULATE changes filters, and the changed filters still travel through the same relationships. If a CALCULATE argument filters 'Product'[Color], the effect reaches Sales through the relationship. If it filters Sales[Quantity], the effect stops at Sales unless a bidirectional path exists. Predicting the result of a CALCULATE expression therefore needs two answers: which columns are filtered after the modification, and which tables those filters reach.
The next chapters build on this. They cover row context, which does not filter and does not propagate through relationships in the same way, and then CALCULATE itself.
Exercise
A matrix shows Total Sales by 'Product'[Category]. A separate card shows COUNTROWS ( 'Product' ). A slicer on Sales[Quantity] selects values above 2. The card does not change. Why, and how could you make one measure count only products that have sales in the filtered range without changing the model?
Show answer
The relationship between 'Product' and Sales is single-direction, from the one side ('Product') to the many side (Sales). The slicer filters Sales, and the filter does not travel back to 'Product', so all products are still counted. To count only products with matching sales without changing the model, use a measure such as COUNTROWS ( FILTER ( 'Product', NOT ISEMPTY ( RELATEDTABLE ( Sales ) ) ) ), or wrap COUNTROWS ( 'Product' ) in CALCULATE with CROSSFILTER ( Sales[ProductKey], 'Product'[ProductKey], BOTH ).
Exercise
A model has an active relationship from Sales[OrderDate] to 'Date'[Date] and an inactive one from Sales[ShipDate] to 'Date'[Date]. A matrix has 'Date'[Year] on rows and Total Sales as the value. Which date does each year row use, and what does the inactive relationship contribute?
Show answer
Each year row uses the order date, because filters from 'Date' propagate only through the active relationship. The inactive relationship contributes nothing to the filter propagation unless a measure activates it, for example with USERELATIONSHIP inside CALCULATE.