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
powerbihelp87
Helper III
Helper III

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
Community Champion
Community Champion

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
Community Champion
Community Champion

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
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.