Forum Discussion

powerbihelp87's avatar
6 years ago
Solved

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
  • 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]
    )

     

6 Replies

  • AntrikshSharma's avatar
    AntrikshSharma
    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]
    )

     

    • powerbihelp87's avatar
      powerbihelp87
      Helper V

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

       

      thank you!!!!!

    • powerbihelp87's avatar
      powerbihelp87
      Helper V

      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?

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

       

       

      • AntrikshSharma's avatar
        AntrikshSharma
        Community Champion

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

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