Sub topic 4
How filters travel across relationships
This chapter assumes you know what a one-to-many relationship is, can write simple aggregations such as SUM and COUNTROWS, and can tell a measure from a calculated column. It also assumes you have seen a filter context built by a slicer or a report visual. Here you learn how that filter context moves from one table to another.
Why propagation matters
A filter context is a set of filters on columns. A slicer on Product[Color] filters the Product table. But Sales Amount reads the Sales table, and Sales has no Color column. The result changes anyway, because the filter on Product is carried over to Sales through a relationship.
This is called filter propagation. It is the reason a star schema works: you filter a small descriptive table, and the large fact table reacts.
Every example in this chapter uses this model:
| Table | Role | Columns used |
|---|---|---|
| `Product` | Dimension (one side) | `ProductKey`, `Color`, `Category` |
| `Customer` | Dimension (one side) | `CustomerKey`, `Country` |
| `Sales` | Fact (many side) | `ProductKey`, `CustomerKey`, `Quantity`, `Unit Price` |
Sales[ProductKey] relates to Product[ProductKey], and Sales[CustomerKey] relates to Customer[CustomerKey]. Both relationships are one-to-many, with the one side on the dimension.
The default direction: one side to many side
A relationship has a filter direction. In the common case, the direction goes from the one side to the many side. A filter on Product reaches Sales. A filter on Sales does not reach Product.
Take this measure:
Sales Amount =
SUMX ( Sales, Sales[Quantity] * Sales[Unit Price] )Put Product[Color] on the rows of a table visual. For the row "Red", the filter context contains Product[Color] = "Red". DAX works in this order:
- The filter keeps only the
Productrows whereColoris "Red". - The relationship passes the surviving
ProductKeyvalues toSales. Saleskeeps only rows whoseProductKeyis among those values.SUMXiterates over thoseSalesrows.
You never wrote a join. The relationship supplies it, and DAX applies it every time a filter touches the one side.
The effect is also cumulative. If a slicer filters Customer[Country] to "France" and the visual row is "Red", Sales receives two filters. Only rows that satisfy both stay. Filters from different dimensions combine with AND semantics on the fact table.
What does not propagate
Filters do not travel backwards by default. Suppose you filter Sales to a single row, for example inside a FILTER on Sales. The Product table still shows every product. That is why this measure is not what it looks like:
Products Sold =
COUNTROWS ( Product )A visual that filters Customer[Country] to "France" gives the same Products Sold for France and for Germany. The filter on Customer reaches Sales, but it stops there. It never travels from Sales back up to Product, so COUNTROWS ( Product ) counts all products.
If you want products that have sales in the current context, you must make Sales filter Product in the expression. One way is to count the distinct keys in the filtered fact table:
Products Sold =
DISTINCTCOUNT ( Sales[ProductKey] )This works because Sales is filtered, and you read the key column from the filtered table itself. No backward propagation is needed.
Chains of relationships
Propagation continues along a chain, as long as every link points the right way. Suppose you add a Category table with a one-to-many relationship to Product. A filter on Category[Name] flows to Product, and then from Product to Sales. Each hop is a separate relationship, and each follows the one-to-many direction.
Two consequences follow:
- A chain is only as strong as its weakest link. If one relationship in the path is inactive or points the wrong way, the filter stops there.
- A table can be filtered by several paths. DAX allows only one active relationship path between two tables, which keeps the result unambiguous.
Both-direction filtering
A relationship can be set to filter in both directions. This is called bidirectional filtering, or cross-filter direction "Both". With it, a filter on Sales also reaches Product.
Turn that on for the Sales–Product relationship. Now COUNTROWS ( Product ) returns the number of products that have at least one Sales row in the current filter context. The "France" example from earlier would count only the products sold to French customers.
This looks convenient, and it is sometimes the right choice, but it has costs:
- Ambiguity. With several bidirectional relationships, a filter can reach a table by more than one path. The engine may refuse to create a relationship that would make the model ambiguous.
- Performance. Each filter now travels farther, and the engine does more work.
- Surprising totals. Dimensions start filtering each other, so results that were independent become dependent.
A narrower option is to enable the direction only inside one measure, with CROSSFILTER:
Products Sold Bidirectional =
CALCULATE (
COUNTROWS ( Product ),
CROSSFILTER ( Sales[ProductKey], Product[ProductKey], BOTH )
)The model stays one-directional, and only this calculation gets the two-way behaviour. CALCULATE itself is the subject of a later chapter. For now, read it as "evaluate the first argument after changing how the model behaves."
Inactive relationships
A model can hold more than one relationship between the same two tables, but only one can be active. Suppose Sales has both OrderDate and ShipDate, each related to a Date table. Only one of them filters Sales by default. The inactive one is stored and does nothing until a calculation asks for it with USERELATIONSHIP:
Sales by Ship Date =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] )
)Within that calculation, the ship-date relationship carries the filter, and the order-date relationship is ignored. This is also a propagation rule: a filter only travels along active relationships unless you say otherwise.
Blank rows and the unknown member
Propagation has an edge case worth knowing. Suppose Sales contains a row with ProductKey = 999, and Product has no row with that key. The relationship is broken for that row, which is called a referential integrity violation.
DAX handles this by adding a blank row to the one-side table. The orphan Sales rows are attached to it. You may see a "(Blank)" entry in a visual grouped by Product[Color]. Its Sales Amount is real money that belonged to no product.
Two points matter for propagation:
- Orphan rows are not lost when no filter is active. They are included in the grand total.
- Once a filter selects a specific color, the blank member is excluded, so orphan rows disappear from the result.
The totals of a filtered view and an unfiltered view can therefore disagree for reasons unrelated to your formula. Fix this in the data, by making sure every foreign key exists in its dimension.
Seeing propagation in a query
You can check what a filter does by evaluating a table expression. In DAX Studio, DAX query view, or any tool that runs queries, this returns the Sales rows reached by a filter on Product:
EVALUATE
CALCULATETABLE (
Sales,
Product[Color] = "Red"
)The result lists only Sales rows whose product is red. Replace Sales with Product and the query returns every product again if the relationship is one-directional and the filter was applied elsewhere. Running small experiments like this is the fastest way to build intuition.
Summary of the rules
| Situation | Does the filter propagate? |
|---|---|
| One side to many side, active relationship | Yes |
| Many side to one side, default direction | No |
| Many side to one side, direction set to Both | Yes |
| Through a chain of one-to-many relationships | Yes, one hop at a time |
| Through an inactive relationship | No, unless `USERELATIONSHIP` is used |
| Rows with no matching key | Grouped under a blank member on the one side |
Common errors
- Reading a dimension with
COUNTROWSand expecting it to reflect sales. The filter does not travel up. Count keys in the fact table or use a deliberate bidirectional filter. - Turning on bidirectional filtering to fix one measure. It changes every calculation in the model. Prefer
CROSSFILTERin the measure that needs it. - Expecting an inactive relationship to filter. It must be activated with
USERELATIONSHIPinsideCALCULATE. - Blaming DAX for totals that differ with and without a filter. Check for orphan keys and the blank member first.
Exercise
A slicer on Customer[Country] is set to "France". A measure Product Count = COUNTROWS ( Product ) shows the same number as with no slicer. The Sales–Product and Sales–Customer relationships are both one-to-many with default single-direction filtering. Why does the number not change, and what is a measure that counts only the products bought by French customers without changing the model?
Show answer
The slicer filters Customer, and the filter propagates to Sales (one side to many side). It cannot continue from Sales to Product, because that would be many side to one side, and the default direction does not allow it. COUNTROWS ( Product ) therefore sees all products. Use DISTINCTCOUNT ( Sales[ProductKey] ), which counts keys in the already filtered Sales table. Alternatively, wrap COUNTROWS ( Product ) in CALCULATE with CROSSFILTER ( Sales[ProductKey], Product[ProductKey], BOTH ).
Exercise
Sales has 10 rows with ProductKey = 999, which does not exist in Product. A table visual shows Sales Amount by Product[Color]. Where do those 10 rows appear, and what happens to them when a slicer selects the color "Red"?
Show answer
They appear under a "(Blank)" row, because DAX adds a blank member to the one-side table for unmatched keys. They are part of the grand total when no filter is active. Selecting "Red" filters Product to red products, the blank member is not among them, and the 10 rows no longer reach Sales, so they drop out of the result.