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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Saxon10
Post Prodigy
Post Prodigy

SUMIFS with multiple columns with DAX

 

Hi,

 

How can I do sumifs in Power BI based on the below mentioned data.

 

In Excel I am apply the following formula =IF(OR($C3="Not Pair",SUMIFS(D$3:D$73,A$3:A$73,A3,C$3:C$73,C3)=1),$B3,"Not Okay") to achieve my final output.

 

I am looking for new calculated column option.

 

 

ItemColour CodeColour CodeUnique CountDesired Result
123OrangeA11Orange
124GreenA11Green
125OrangeA21Orange
126GreenA21Green
127OrangeNot Pair1Orange
128OrangeNot Pair1Orange
135OrangeA11Orange
135GreenA21Green
136OrangeA21Not Okay
136GreenA21Not Okay
137OrangeA11Orange
137OrangeNot Pair1Orange
137OrangeNot Pair1Orange
138GreenA11Green
138OrangeNot Pair1Orange
138OrangeNot Pair1Orange
139OrangeA11Orange
139OrangeNot Pair1Orange
140GreenA11Green
140OrangeNot Pair1Orange
141OrangeA21Orange
141OrangeNot Pair1Orange
141OrangeNot Pair1Orange
142GreenA21Green
142OrangeNot Pair1Orange
142OrangeNot Pair1Orange
143GreenA11Green
143GreenA21Green
143OrangeNot Pair1Orange
144OrangeA11Not Okay
144GreenA11Not Okay
144OrangeNot Pair1Orange
145OrangeA11Not Okay
145GreenA11Not Okay
145OrangeA21Not Okay
145GreenA21Not Okay
147GreenA20.5Green
147GreenA20.5Green
148OrangeA10.5Orange
148OrangeA10.5Orange
149GreenA10.5Green
149GreenA10.5Green
150OrangeA11Orange
150OrangeA21Orange
151GreenA11Green
151GreenA21Green
152OrangeA11Orange
152OrangeNot Pair1Orange
152OrangeA21Orange
153OrangeA11Not Okay
153GreenA11Not Okay
153OrangeA21Orange
1999OrangeA21Not Okay
1999GreenA21Not Okay
1999OrangeA11Orange
155GreenA10.5Green
155GreenA21Not Okay
156OrangeA20.5Orange
156GreenA10.5Green
157OrangeNot Pair1Orange
157OrangeNot Pair1Orange
154OrangeA11Not Okay
154OrangeA21Orange
154GreenA11Not Okay
155OrangeA21Not Okay
155GreenA10.5Green
155OrangeNot Pair1Orange
156OrangeA20.5Orange
156GreenA10.5Green
156OrangeNot Pair1Orange
156OrangeNot Pair1Orange

 

 

 

2 ACCEPTED SOLUTIONS
AlexisOlson
Super User
Super User

You can't have two columns with the same name, so I change the first to "Colour" and second to "Code":

 

Result =
VAR SumIfs =
    CALCULATE (
        SUM ( Table1[Unique Count] ),
        ALLEXCEPT ( Table1, Table1[Item], Table1[Code] )
    )
RETURN
    IF ( Table1[Code] = "Not Pair" || SumIfs = 1, Table1[Colour], "Not Okay" )

 

View solution in original post

Hi @Saxon10 ,

 

Please add the ROUND function to the formula of AlexisOlson.

 

image.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

10 REPLIES 10
AlexisOlson
Super User
Super User

You can't have two columns with the same name, so I change the first to "Colour" and second to "Code":

 

Result =
VAR SumIfs =
    CALCULATE (
        SUM ( Table1[Unique Count] ),
        ALLEXCEPT ( Table1, Table1[Item], Table1[Code] )
    )
RETURN
    IF ( Table1[Code] = "Not Pair" || SumIfs = 1, Table1[Colour], "Not Okay" )

 

@AlexisOlson ,

 

Thanks for your respones and sorry for the late reply.
Your solution almost working fine but I recevied incorrect result were the same itms has repeat multiple times

Saxon10_0-1632326477967.png

 

 


Hi @Saxon10 ,

 

Please add the ROUND function to the formula of AlexisOlson.

 

image.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@Saxon10 ROUND is a good modification but rounding to zero decimal places might be a bit too round. If you run into trouble, try ROUND ( SumIfs, 1 ) instead.

@AlexisOlson ,

 

Thanks for your tips and advise. I will test both scenario at my end.

 

Thanks for your reply and your solution. 

 

Your solution working well. Thank you.

I'm guessing you have some kind of rounding error so that Unique Count isn't adding up to exactly 1.

 

I don't understand why you have duplicated rows, so it's hard to suggest a fix.

amitchandak
Super User
Super User

@Saxon10 , Try a new column like

 

new col =
var _1 = countx(filter(Table, [Item] && earlier([Item]) && [Colour Code] <> "Not Pair"), [Item])
return
if([Colour Code] = "Not Pair" || isblank(_1) || _1=1, [Colour], "Not Okay")

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

I am receeving error if I apply your code "The syntax for 'Table' is incorrect. (DAX(var _1 = countx(filter(Table, [Item] && earlier([Item]) && [Colour Code] <> "Not Pair"), [Item])returnif([Colour Code] = "Not Pair" || isblank(_1) || _1=1, [Colour Code], "Not Okay"))).

Saxon10_0-1632252239374.png

 



thanks for your reply.

 

I am receving the error can't convert value "item column" of type text to type true /false.

 

Could you please share your PBI. 

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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