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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
powerbihelp87
Helper IV
Helper IV

Help with DAX for SumX and Filter function on multiple columns

I need to calculate the sum of two columns based on filters. I tried:

 

SUMX(FILTER('Test Table','Test Table'[Code="10023" || 'Test Table'[Code]="10039" && 'Test Table'[Category]="az" && 'Test Table'[Category]="ac" ),'Test Table'[ Amount]) it did not work.

 

Can someone please help guide me how I can get the sum for codes 10039 or 10023 where categories are ac or az. the actual table has more columns like date, brand which i need to be able to filter on dynamically

 

CategoryCodeAmount
ab10023192
ac100393092
kj1002349
ko1093242
ab1098402
ac100234
az100392543
ab1890432
ac100239323
kj103043894
ko1930493
ab2931292
ac2930923
az10023587
ab100398437
ac29308329
kj1002394389
ko10039289
ab230494
ac29047
az1002321
1 ACCEPTED SOLUTION
AntrikshSharma
Super User
Super User

Try this:

=
SUMX (
    FILTER (
        ALLSELECTED ( 'Test Table' ),
        ( 'Test Table'[Code] = "10023"
            || 'Test Table'[Code] = "10039" )
            && ( 'Test Table'[Category] = "az"
            || 'Test Table'[Category] = "ac" )
    ),
    'Test Table'[ Amount]
)

 

View solution in original post

6 REPLIES 6
AntrikshSharma
Super User
Super User

Try this:

=
SUMX (
    FILTER (
        ALLSELECTED ( 'Test Table' ),
        ( 'Test Table'[Code] = "10023"
            || 'Test Table'[Code] = "10039" )
            && ( 'Test Table'[Category] = "az"
            || 'Test Table'[Category] = "ac" )
    ),
    'Test Table'[ Amount]
)

 

@AntrikshSharma  actually it works at total level and when I want to filter.  But if I add a filter like plant into a table it shows total and won't break it down unless i filter.   but once i filter on lets say C01 the numbers appear?

powerbihelp87_0-1595916570541.png

once i filter numbers break down properly.  I think i solved this by removing the ALLSELECTED

powerbihelp87_1-1595916614161.png

 

 

Cool, I thought you wanted total for the conditions plus anything that is selected through slicers.

@AntrikshSharma  Yes, you are right initially I did but then realized I need to see more data.  thanks!

Amazing! Thank you so much I was mixing up the && || and didn't include ALL!

 

thank you!!!!!

parry2k
Super User
Super User

@powerbihelp87 try this measure

 

SUM ( 'Test Table'[Amount]),
'Test Table','Test Table'[Code] IN {"10023","10039"},
'Test Table'[Category] IN {"az""ac"} 
)

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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