CROSSFILTER
As a filter of CALCULATE, sets which way a relationship filters for the calculation: one way, both ways, or not at all.
Group: Relationships. Compatible with DAX.
Syntax
CROSSFILTER ( <columnName1>, <columnName2>, <direction> )
| Parameter | Type | Description |
|---|---|---|
columnName1 | Column | One column of the relationship, usually the one on its many side. |
columnName2 | Column | The relationship's other column. |
direction | Keyword | BOTH, NONE, ONEWAY, ONEWAY_LEFTFILTERSRIGHT or ONEWAY_RIGHTFILTERSLEFT. |
Returns
Filter. No value of its own: it changes how the relationship filters, for the CALCULATE it is in.
Remarks
BOTHlets the relationship filter both ways: a filter on Places then reaches Products through Sales.NONEswitches the relationship off.ONEWAYfilters from the one side to the many side only, as a relationship does by default.ONEWAY_LEFTFILTERSRIGHTandONEWAY_RIGHTFILTERSLEFTname the filtering column by its place in the call. On a many-to-one relationship the one side must be the one that filters: asking the many side alone to filter is an error.- The two columns may come in either order.
- It works only as a filter of
CALCULATEorCALCULATETABLE, and the columns must be those of a relationship of the model; otherwise it is an error. - Write the direction as a keyword, without quotes.
- Filtering both ways can make numbers harder to follow, and slower. Change it in the one measure that needs it rather than in the model.
Examples
Products sold at each kind of place
Normally a filter on Places does not reach Products, so every row sees all four products. With BOTH, it reaches them through Sales: the depot sold nothing, so no product is left.
EVALUATE
ADDCOLUMNS (
VALUES ( Places[Kind] ),
"Products", COUNTROWS ( Products ),
"Products sold there",
CALCULATE ( COUNTROWS ( Products ), CROSSFILTER ( Sales[Product], Products[Product], BOTH ) )
)
ORDER BY Places[Kind]
| Places[Kind] | Products | Products sold there |
|---|---|---|
| Depot | 4 | (blank) |
| Shop | 4 | 4 |
A relationship switched off
With NONE, the category of the row no longer reaches Sales: each row has every liter.
EVALUATE
SUMMARIZECOLUMNS (
Products[Category],
"Liters", [Liters sold],
"Relationship off", CALCULATE ( [Liters sold], CROSSFILTER ( Sales[Product], Products[Product], NONE ) )
)
ORDER BY Products[Category]
| Products[Category] | Liters | Relationship off |
|---|---|---|
| Beer | 1505389 | 1806463 |
| Cider | 301074 | 1806463 |
Related functions
USERELATIONSHIP, CALCULATE, ALLCROSSFILTERED, ISCROSSFILTERED, TREATAS.