Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Sum Column with Multiple Criteria

Hi All, 

 

Trying to acheive something like this in "New Column", using a DAX function. 

 

I want to sum the Sales values for matching Year, Month, and Cat1 rows. 

YearMonthCat1Cat2SalesNew Column
2019FebQuickFizz13
2019FebQuickBuzz23
2019FebBrownFizz37
2019FebBrownBuzz47
2019MarchQuickFizz511
2019MarchQuickBuzz611
2019MarchBrownFizz715
2019MarchBrownBuzz815

 

Thanks!

  • Hi Anonymous ,

    You also could try this calculated column.

    Column =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Year] = EARLIER ( 'Table'[Year] )
                && 'Table'[Month] = EARLIER ( 'Table'[Month] )
                && 'Table'[Cat1] = EARLIER ( 'Table'[Cat1] )
        )
    )
    

    Here is the output.

    Hope this can help you.

    Best Regards,

    Cherry

     

4 Replies

  • az38's avatar
    az38
    Community Champion

    Hi Anonymous 

    try new measure

    Measure = calculate(sum(Tbl[Sales]);ALLEXCEPT(Tbl;Tbl[Year];Tbl[Month];Tbl[Cat1]))
    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks az38! I tried that and it worked before, but it's giving me values for Sales that don't exist at all, which is strange. 

       

      Any insight?

      • az38's avatar
        az38
        Community Champion

        Anonymous 

        i think, this is the easiest case of dax-usage

        what kind of incorrect values it's giving you? could you show an example to try to debug? maybe some filters?

  • v-piga-msft's avatar
    v-piga-msft
    Resident Rockstar

    Hi Anonymous ,

    You also could try this calculated column.

    Column =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Year] = EARLIER ( 'Table'[Year] )
                && 'Table'[Month] = EARLIER ( 'Table'[Month] )
                && 'Table'[Cat1] = EARLIER ( 'Table'[Cat1] )
        )
    )
    

    Here is the output.

    Hope this can help you.

    Best Regards,

    Cherry