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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
navarrobr
Frequent Visitor

SUMIF Equivalent in DAX

Hi everyone!

 

I have a simple situation here, but can't figure out how to solve it. Imagine the following data model:

 

DAX

 

What I need is a measure (or maybe a column?) that shows the sum of Hours when the Project Company is different from the User company. I tried this:

 

Intercompany Hours = CALCULATE (Sum(Hour[Hours]);Project[Company]<>User[Company])

 

It does not work... I would appreciate any help!

1 ACCEPTED SOLUTION

Now it worked! Smiley Happy

 

Intercompany Hours = SUMX(filter('Hour';related(Project[Project_company])<>related(User[User_company]));sum('Hour'[Hours]))

 

solution.png

View solution in original post

6 REPLIES 6
vanessafvg
Super User
Super User

i dont think your data is modelled correctly.  Firstly how are the joined together?  you need some kind of unique id that flows through to all tables ie. both project and user s should have a project id?  or is that link there?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Hi, thanks for answering!

 

The Hour table is my Fact Table, it has foreign keys from my two Dimension Tables (Project and User) and one measure field (hours). Is that clearer now?

I would think you would want to change to SUMX and use RELATED

 

CALCULATE( 
   SUMX (Hours, Hours[Hours]),
   RELATED(Project[Company]) <> RELATED(User[Company]) 
)

 

Hope this helps,

David 

Hi David and Vanessa,

 

Here is a link to my example file: http://www.syscope.com.br/files/example.zip

 

 

Here is the data model:

data_model.png

 

Here is the data, my expression should show the 10 hours below (where the user company is different from the project company):

 

data_example.png

 

This is the error I got with my formula:

error_marcelo.png

 

And David, this is the error I got from your formula:

 

error_david.png

 

Now it worked! Smiley Happy

 

Intercompany Hours = SUMX(filter('Hour';related(Project[Project_company])<>related(User[User_company]));sum('Hour'[Hours]))

 

solution.png

ah ok makes sense, so what error are you getting?  





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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