Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
HobbyS
Regular Visitor

CROSSFILTER and wrong Grand Total

I have to following tables:

 

Employees (Dim-Table):

HobbyS_6-1677590438845.png

 

Transactions (Fact-Table):

HobbyS_7-1677590458363.png

 

And the following relationship:

HobbyS_3-1677589961003.png

 

I would like to show the highest Rate of Employees, that is used in Transactions, grouped by Division. I get correct results for each Division, but the Grand Total shows the highest rate of any employee, although that employee is not part of any transaction. 

 

 

MaxRate: =CALCULATE(MAXX(Employees[Rate]);CROSSFILTER(Employees[PK_Emp];Transactions[FK_Emp];Both))

 

 

Result:

HobbyS_5-1677590387917.png

 

Thank you for your help in advance.

1 ACCEPTED SOLUTION
MAwwad
Solution Sage
Solution Sage

 

The reason you are getting the wrong Grand Total in your visual is because the calculation is not taking into account the fact that some employees may not have any transactions. Since you are using the Both direction in the CROSSFILTER function, it is returning the maximum rate of any employee in the Employees table regardless of whether they have transactions or not.

To fix this issue, you can modify your MaxRate calculation by using the FILTER function to only consider employees who have transactions:

 

 
MaxRate := CALCULATE( MAXX( FILTER( Employees, COUNTROWS(RELATEDTABLE(Transactions)) > 0 ), Employees[Rate] ), CROSSFILTER(Employees[PK_Emp], Transactions[FK_Emp], Both) )
 

This modified calculation first filters the Employees table to only include employees who have transactions by using the RELATEDTABLE function to get a table of transactions related to each employee, and then counting the number of rows in that table. The MAXX function is then applied to the filtered table to return the maximum rate of those employees. Finally, the CROSSFILTER function is used to ensure the calculation is performed in both directions between the Employees and Transactions tables.

With this modification, the MaxRate calculation should now return the correct maximum rate for each division, as well as for the Grand Total.

View solution in original post

2 REPLIES 2
HobbyS
Regular Visitor

Thank you @MAwwad 

 

That is exactly what I was looking for. I guess CROSSFILTER establiches a bi-directional relationship in the form of a cross-join. So each record of "Employees" is included. Not like a "left-join" where you would only have Employees that have a corresponding record in "Transactions"?

MAwwad
Solution Sage
Solution Sage

 

The reason you are getting the wrong Grand Total in your visual is because the calculation is not taking into account the fact that some employees may not have any transactions. Since you are using the Both direction in the CROSSFILTER function, it is returning the maximum rate of any employee in the Employees table regardless of whether they have transactions or not.

To fix this issue, you can modify your MaxRate calculation by using the FILTER function to only consider employees who have transactions:

 

 
MaxRate := CALCULATE( MAXX( FILTER( Employees, COUNTROWS(RELATEDTABLE(Transactions)) > 0 ), Employees[Rate] ), CROSSFILTER(Employees[PK_Emp], Transactions[FK_Emp], Both) )
 

This modified calculation first filters the Employees table to only include employees who have transactions by using the RELATEDTABLE function to get a table of transactions related to each employee, and then counting the number of rows in that table. The MAXX function is then applied to the filtered table to return the maximum rate of those employees. Finally, the CROSSFILTER function is used to ensure the calculation is performed in both directions between the Employees and Transactions tables.

With this modification, the MaxRate calculation should now return the correct maximum rate for each division, as well as for the Grand Total.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.