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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jhobzvel
Frequent Visitor

Incorrect Sum of Columns and Rows in Matrix

I have 3 simple tables to show the example of my issue. There were no formulas or measures here.

Employee - List of employees and their position

Salary - Monthly salary of employees and it increases monthly

Department - Department of employees listed monthly since they may be transferred

Date Table

 

My goal is to have a total Salary per Department and Employee like below and I am almost there but as you can see, the row and column totals were wrong which is why I posted here. There seems to be a problem with relationship and I can't pinpoint where.

 

Example: Anita is part of Sales in January, IT in Ferbruary and Marketing in March. So the salary total of Anita under IT should be 75 and not 225. 

Also, each departments column total is the same like 350 for January, 525 for Feb and 700 for March which are incorrect.

 

jhobzvel_0-1650528117385.png

 

Relationship is like this:

jhobzvel_1-1650528223703.pngjhobzvel_2-1650528266160.png

 

Employee table:

jhobzvel_0-1650528812254.png

Salary table:

jhobzvel_1-1650528837292.png

 

Department Table:

jhobzvel_2-1650528859386.png

 

2 ACCEPTED SOLUTIONS
DataInsights
Super User
Super User

@jhobzvel,

 

Try this measure:

 

Total Salary =
CALCULATE (
    SUM ( Salary[Salary] ),
    CROSSFILTER ( Department[Employee], Employee[Employee], BOTH ),
    CROSSFILTER ( Department[Month], 'Date'[Date], BOTH )
)

 

The reason you need the CROSSFILTER function is that the relationships are unidirectional, meaning that filters can't flow from Department to Employee, for example. This is the correct way to design a data model. Some developers use bidirectional relationships to achieve this, but numerous issues can result. Always use unidirectional relationships.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

@jhobzvel,

 

Try the solution shown below. The Department table is a Type 2 Slowly Changing Dimension that tracks the association of Employee and Department over time. The concept is to pull the relevant Department into the fact table, and exclude the Department table from the star schema.

 

1. In the Salary table, create a calculated column:

 

Department = 
LOOKUPVALUE (
    Department[Department],
    Department[Employee], Salary[Employee],
    Department[Month], Salary[Month]
)

 

2. Remove relationships with the Department table:

 

DataInsights_0-1650638744755.png

 

3. Create measure:

 

Total Salary = SUM ( Salary[Salary] )

 

4. Create matrix using fields from the Date, Employee, and Salary tables:

 

DataInsights_1-1650638985714.png

 

Here's a great video on the topic:

 

https://www.youtube.com/watch?v=tKeaQpWynzg 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
DataInsights
Super User
Super User

@jhobzvel,

 

Try this measure:

 

Total Salary =
CALCULATE (
    SUM ( Salary[Salary] ),
    CROSSFILTER ( Department[Employee], Employee[Employee], BOTH ),
    CROSSFILTER ( Department[Month], 'Date'[Date], BOTH )
)

 

The reason you need the CROSSFILTER function is that the relationships are unidirectional, meaning that filters can't flow from Department to Employee, for example. This is the correct way to design a data model. Some developers use bidirectional relationships to achieve this, but numerous issues can result. Always use unidirectional relationships.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I got an error like this when I created the measure and added it in the matrix.

jhobzvel_0-1650595477629.png

 

@jhobzvel,

 

Try the solution shown below. The Department table is a Type 2 Slowly Changing Dimension that tracks the association of Employee and Department over time. The concept is to pull the relevant Department into the fact table, and exclude the Department table from the star schema.

 

1. In the Salary table, create a calculated column:

 

Department = 
LOOKUPVALUE (
    Department[Department],
    Department[Employee], Salary[Employee],
    Department[Month], Salary[Month]
)

 

2. Remove relationships with the Department table:

 

DataInsights_0-1650638744755.png

 

3. Create measure:

 

Total Salary = SUM ( Salary[Salary] )

 

4. Create matrix using fields from the Date, Employee, and Salary tables:

 

DataInsights_1-1650638985714.png

 

Here's a great video on the topic:

 

https://www.youtube.com/watch?v=tKeaQpWynzg 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




It fixed the issue I am facing and you save so much of my time! Thank you so much @DataInsights.

I appreaciate your help and your time in checking this!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.