Professional Documents
Culture Documents
(USERELATIONSHIP vs CROSSFILTER)
USERELATIONSHIP
CROSSFILTER
-Sourav Pattanayak
Sourav Pattanayak
Navigating the Data Maze: USERELATIONSHIP vs. CROSSFILTER
The Dynamics
Welcome to the fascinating world of data modeling and analysis using Power BI and DAX functions. Get
ready to dive into the intricacies of USERELATIONSHIP and CROSSFILTER, where tables connect,
relationships work their magic, and clarity emerges from the occasional confusion.
Sourav Pattanayak
DATA MODELLING & RELATIONSHIPS
First we need to check the data modelling and the active and inactive relationship before jumping
further.
Data Modelling:
We have two tables having both active and inactive relationship with each other.
Active Relationship:
Inactive Relationship:
Now we will see how USERELATIONSHIP changes the Data Modelling in it’s use.
Sourav Pattanayak
THE CONVENIENT SUM FUNCTION
Sum Function:
At first, we do want to know the Total amount of sales and for that using the SUM function is enough.
Isn’t it?
Syntax:
SUM(Table[column])
Consider the following two tables, ‘Sales Data’ and date_dimension.
Table->sales_data
Table-> date_dimension
Date Year Month Week
05-07-2024 Friday July 6
27-06-2024 Thursday June 11
19-05-2024 Sunday May 17
26-04-2024 Friday April 21
17-03-2024 Sunday March 26
9-02-2024 Friday February 27
…….and so on …….and so on …….and so on …….and so on
Now, using the SUM function,
total_sales = SUM(sales_data[Amount])
By using a matrix visual and visualizing the sales by month,we get sales by month,
The output table will look like
Sourav Pattanayak
USERELATIONSHIP
Definition:
This DAX function is used to specify a relationship to be used in a calculation. It overrides any existing
active relationships between tables in the data model for the duration of the calculation.
Syntax:
USERELATIONSHIP(<columnName1>,<columnName2>)
Table-> date_dimension
Date Year Month Week
05-07-2024 Friday July 6
27-06-2024 Thursday June 11
19-05-2024 Sunday May 17
26-04-2024 Friday April 21
17-03-2024 Sunday March 26
9-02-2024 Friday February 27
…….and so on …….and so on …….and so on …….and so on
Now, using USERELATIONSHIP Function,
Total Sales by Week =
CALCULATE(
SUM(sales_data[Amount]), USERELATIONSHIP(date_dimension[Date],sales_data[Weekday]))
Sourav Pattanayak
CROSSFILTER
Definition:
This DAX function is used to control how filters flow between related tables. It specifies the direction of
the filter propagation across a relationship. This function enables us to determine whether filtering should
occur in both directions (both tables) or only in one direction (one table) across the relationship.
Syntax:
Table-> date_dimension
Date Year Month Week
05-07-2024 Friday July 6
27-06-2024 Thursday June 11
19-05-2024 Sunday May 17
26-04-2024 Friday April 21
17-03-2024 Sunday March 26
9-02-2024 Friday February 27
…….and so on …….and so on …….and so on …….and so on
Now, using USERELATIONSHIP Function,
crossfilter sales = CALCULATE( SUM(sales_data[Amount]),
CROSSFILTER(date_dimension[Date], sales_data[Weekday], BOTH))
The output tables will look like(Using the both date and weekday columns of the two tables)
Sourav Pattanayak
CONFUSION ZONE
What do we see?:
Upon creating card visuals of total amount of sales it is been seen that the total amount is same for all
three DAX uses(SUM/USERELATIONSHIP & CROSSFILTER).
2. USERELATIONSHIP:
- But with `USERELATIONSHIP`, changing the date slicer might not affect the sales amounts. Only the
weekday slicer (attached to the sales table) can change the sales amounts. That's because
`USERELATIONSHIP` keeps the relationship fixed and slicers on the date table might not influence it.
Sourav Pattanayak
THE TRAFFIC SYSTEM
5. Impact on Slicers: When users switch between different slicers, it's like
changing the road signs; the measure responds based on the currently active
relationship, prioritizing the one set by USERELATIONSHIP over the default
relationship.
Sourav Pattanayak
Repost if you find it helpful.
for more.
Sourav Pattanayak