CROSSFILTER DAX Function (Relationships management)
Specifies cross filtering direction to be used in the evaluation of a DAX expression. The relationship is defined by naming, as arguments, the two columns that serve as endpoints.
Syntax
Parameter | Attributes | Description |
---|---|---|
LeftColumnName |
Left Column. |
|
RightColumnName |
Right Column. |
|
CrossFilterType |
The third argument to the CROSSFILTER function should be 0 for None, or 1 for OneWay, or 2 for Both, or 3 for OneWay_RightFiltersLeft, or 4 for OneWay_LeftFiltersRight. It is also possible to use the words None, OneWay, Both, OneWay_RightFiltersLeft, OneWay_LeftFiltersRight. |
Return values
The function returns no value. The function only sets the cross-filtering direction for the indicated relationship, for the duration of the query.
Remarks
In the case of a 1:1 relationship, there is no difference between the one and both direction.
CROSSFILTER can only be used in functions that take a filter predicate as an argument, for example: CALCULATE, CALCULATETABLE, CLOSINGBALANCEMONTH, CLOSINGBALANCEQUARTER, CLOSINGBALANCEYEAR, OPENINGBALANCEMONTH, OPENINGBALANCEQUARTER, OPENINGBALANCEYEAR, TOTALMTD, TOTALQTD and TOTALYTD functions.
CROSSFILTER uses existing relationships in the model, identifying relationships by their ending point columns.
In CROSSFILTER, the cross-filtering setting of a relationship is not important; that is, whether the relationship is set to filter one, or both directions in the model does not affect the usage of the function. CROSSFILTER will override any existing cross-filtering setting.
An error is returned if any of the columns named as an argument is not part of a relationship or the arguments belong to different relationships.
If CALCULATE expressions are nested, and more than one CALCULATE expression contains a CROSSFILTER function, then the innermost CROSSFILTER is the one that prevails in case of a conflict or ambiguity.
The arguments OneWay_RightFiltersLeft and OneWay_LeftFiltersRight can be used in many-to-many and one-to-many relationship types, but not in the one-to-one relationship type.
When the cross-filter type OneWay_RightFiltersLeft or OneWay_LeftFiltersRight is used in a one-to-many relationship type, it must be consistent with the only allowed filter propagation, which is one-to-many. If the requested direction is the opposite one, CROSSFILTER returns an error.
CROSSFILTER only changes the cross filter direction applied when the relationship is active. CROSSFILTER does not change the active state of the relationship: USERELATIONSHIP must be used to activate an inactive relationship,.
CROSSFILTER cannot be used when it changes the default filter propagation from a table that has Row-level security (RLS) applied. Consider using TREATAS as a workaround in those cases.
» 1 related function
Examples
-- CROSSFILTER changes the cross-filter direction of a relationship -- The arguments are the columns involved in the relationship and -- the cross-filter direction, which can be BOTH, ONEWAY, NONE DEFINE MEASURE Sales[Customers] = COUNTROWS ( Customer ) MEASURE Sales[CustomersFiltered] = CALCULATE ( [Customers], CROSSFILTER ( Sales[CustomerKey], Customer[CustomerKey], BOTH ) ) MEASURE Sales[ProductsDoesNotFilter] = CALCULATE ( [Customers], CROSSFILTER ( Sales[CustomerKey], Customer[CustomerKey], BOTH ), CROSSFILTER ( Sales[ProductKey], 'Product'[ProductKey], NONE ) ) EVALUATE SUMMARIZECOLUMNS ( 'Product'[Brand], "Customers", [Customers], "Customers Buying", [CustomersFiltered], "Products does not filter Sales", [ProductsDoesNotFilter] )
Brand | Customers | Customers Buying | Products does not filter Sales |
---|---|---|---|
Contoso | 18,869 | 4,346 | 18,869 |
Wide World Importers | 18,869 | 517 | 18,869 |
Northwind Traders | 18,869 | 1,002 | 18,869 |
Adventure Works | 18,869 | 2,587 | 18,869 |
Southridge Video | 18,869 | 5,200 | 18,869 |
Litware | 18,869 | 994 | 18,869 |
Fabrikam | 18,869 | 526 | 18,869 |
Proseware | 18,869 | 495 | 18,869 |
A. Datum | 18,869 | 1,144 | 18,869 |
The Phone Company | 18,869 | 318 | 18,869 |
Tailspin Toys | 18,869 | 4,278 | 18,869 |
Related articles
Learn more about CROSSFILTER in the following articles:
-
Many-to-many relationships in Power BI and Excel 2016
The new DAX available in Excel 2016 and the data model in Power BI and Analysis Services 2016 offer tools to manage many-to-many relationships in a more efficient way than previous version, as described in this article. » Read more
-
Bidirectional relationships and ambiguity in DAX
Activating bidirectional cross-filter in a Tabular data model might create ambiguous paths in the chain of relationships, resulting in very dangerous models as numbers become unpredictable. This article provides a deep explanation of the kind of ambiguity that might appear… » Read more
-
Different options to model many-to-many relationships in Power BI and Tabular
There are two options to model many-to-many relationships using Tabular and Power BI: you can use either a regular bidirectional filter relationship, or a limited unidirectional relationship. In this article, we compare the performance of both options. » Read more
Related functions
Other related functions are:
Last update: Nov 14, 2024 » Contribute » Show contributors
Contributors: Alberto Ferrari, Marco Russo, Kenneth Barber,
Microsoft documentation: https://docs.microsoft.com/en-us/dax/crossfilter-function