Forum Discussion

vidyasagar159's avatar
vidyasagar159
Helper II
6 years ago
Solved

Aggregating multiple columns based on category filter

Hello All,

 

Aggressively learning Power BI and doing a project at the same time. But I am stuck on a logic. Please help. 

I want to Subtract two columns based on the Product category. I want to achieve the below result set. 

 

 

 

 

 

 

Here is the logic I am looking for 
IF Category = Red then (Amount_One) - (Amount_Two) else if Category = Black then (Amount_One) - (Amount_Three)

 

ProductCategoryAmount_OneAmount_TwoAmount_ThreeIF Category = Red then (Amount_One) - (Amount_Two) else if Category = Black then (Amount_One) - (Amount_Three)
ARed100109090
ARed2002080180
ARed3003070270
ARed4004060360
ARed5005050450
ARed6006040540
BBlack7007030670
BBlack8008020780
BBlack9009010890
BBlack100010001000
BBlack1100110-101110
BBlack1200120-201220

Thanks,

Vidya

  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi, vidyasagar159 

     

     

    IF(Table1[Category] = “Red”, [Amount_One]-[Amount_Two], [Amount_One]-[Amount_Three]]

     

     

    Best, 
    Paul

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, vidyasagar159 

     

     

    IF(Table1[Category] = “Red”, [Amount_One]-[Amount_Two], [Amount_One]-[Amount_Three]]

     

     

    Best, 
    Paul

    • vidyasagar159's avatar
      vidyasagar159
      Helper II

      Anonymous 

      Thanks. But I am getting the following error.

       

      A single value for column 'Category' in table 'Table1' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

       

      Thanks,

      -Vidya

      • vidyasagar159's avatar
        vidyasagar159
        Helper II

        Anonymous 

         

        Never Mind. It is working. I used the formula in a measure instead of a calculated column. Thank you for your help.

         

        -Vidya