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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Mikeincairns
Frequent Visitor

No SUMIF in DAX. Please help with this SUM/LOOKUP/FILTER

Hi everyone.  I'm really hoping for a simple and logical solution please.
I am from the Excel world where this would be an easy SUMIF formula, but I am stumped in DAX.  Not sure the best function to apply.
I have two tables but they CANNOT be related in the PBI data model (due to other conflicting relationships).
I think the diagram explains everything......
2024-02-18_235042.png

1 ACCEPTED SOLUTION
Mikeincairns
Frequent Visitor

Jihwan_Kim's solution was a great help, but created a measure.  This was no good because I needed to do further calculateions and required a calculated column.
For others that may need help with SUMIF in DAX, this is what worked in the end.....
Calculated Column: 

Expense = CALCULATE(
SUM(tblExpenses[Amount]),
FILTER(
    tblExpenses,
    tblActivities[ActivityId] = CALCULATE(VALUES(tblExpenses[ActivityID]))
    )
)

 

View solution in original post

6 REPLIES 6
Mikeincairns
Frequent Visitor

Jihwan_Kim's solution was a great help, but created a measure.  This was no good because I needed to do further calculateions and required a calculated column.
For others that may need help with SUMIF in DAX, this is what worked in the end.....
Calculated Column: 

Expense = CALCULATE(
SUM(tblExpenses[Amount]),
FILTER(
    tblExpenses,
    tblActivities[ActivityId] = CALCULATE(VALUES(tblExpenses[ActivityID]))
    )
)

 

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1708277538138.png

 

 

Expense measure: =
SUMX (
    FILTER ( expenses, expenses[activity_id] IN VALUES ( activities[activity_id] ) ),
    expenses[amount]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here and Go to My LinkedIn Page


Thanks so much for the suggestion Jhiwan_Kim.  And a big thank you for the sample file.  You are amazing 🙂
From your file - ultimetly, I want to add Cost_01 + Cost_02 + Expense.
I think this is not possible when we use a Measure.  Perhaps there is another solution to get the Expense using a Calculated Column rather than a Measure???

Hi,

I am not 100% sure if I understood your question correctly, but please try something like below. It is writing a measure.

 

Jihwan_Kim_0-1708317640945.png

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here and Go to My LinkedIn Page


lbendlin
Super User
Super User

Read about TREATAS. It allows you to carry filters between unrelated tables.

Thanks Ibendlin.  So many functions !!!
I have a (sort of) working solution CALCULATE(SUM(FILTER
And Jhiwan_Kim sugested a SUMX(FILTER IN VALUES
I will read about TREATAS and see how that might help.

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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

Top Solution Authors
Top Kudoed Authors