Forum Discussion

bo_afk's avatar
bo_afk
Icon for Post Patron rankPost Patron
5 years ago

Sum values by category in table

I've created a measure to sum my values grouped by 2 categories using the SUM and ALLEXCEPT functions, however it's not calculating the numbers as expected.

Table

Category2Category1ProductIDSales
1BagABC123100
2BagABC123200
1BagXYZ456300
2BagXYZ456400
1ShoesDEF567800
2ShoesDEF567700

 

Measure = CALCULATE(SUM(Value)),ALLEXCEPT(Table,[Category1],[Category2]))

 

When I put the values into the table and include category 2, the correct value is calculated. However, when I remove category2 from the table, the figures change. I would've expected the grouped sum up to category2 to remain but it doesn't.

How can amend my measure to display the expected outcome below?

Current outcome (incorrect)

Exected outcome

Category1ProductIDSalesMeasure
1ABC123100400
2ABC123200600
1XYZ456300400
2XYZ456400600
1DEF567800800
2DEF567700700

5 Replies

  • bo_afk , Try like

     

    Measure = CALCULATE(SUM('Table (2)'[Sales]), REMOVEFILTERS('Table (2)'[Category1],'Table (2)'[Category2]))

     

    • bo_afk's avatar
      bo_afk
      Icon for Post Patron rankPost Patron

      Hi amitchandak, thanks for your suggestion. Unfortunately this hasnt completely worked. It sums it up by productID but not by category 2.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hello bo_afk ,

     

    You better create column instead of measure and try,

    Column = CALCULATE(SUM(Table[Sales]),ALLEXCEPT(Table,Sheet15[Category1],Table[Category2]))

     

    • bo_afk's avatar
      bo_afk
      Icon for Post Patron rankPost Patron

      Hi Anonymous, thanks for the suggestion. This does seem to work however this doesn't dynamically calculate if I apply other filters in the report. Am I really unable to create this as a measure so that the figure changes with filters?