Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Add new Conditional Column

I have a table like below,

2 types of products. I want the last column Margin as calculated like:

For A: It is Revenue - T Price

& For B: It is Revenue - M Price.

How do I set up the Margin column to get the above conditions?

 

Product typeRevenueT PriceM PriceMargin
A4036 40-36
A5450 54-50
B32282732-27
B43403843-38
A3330 33-30
B29272529-25
  • Anonymous  you can write a measure like this

     

    Measure = 
    SWITCH (
        TRUE (),
        MAX ( 'Table 1'[Product type] ) = "A", SUM ( 'Table 1'[Revenue] ) - SUM ( 'Table 1'[T Price] ),
        MAX ( 'Table 1'[Product type] ) = "B", SUM ( 'Table 1'[Revenue] ) - SUM ( 'Table 1'[M Price] )
    )

     

     

     

    or a calculated column

    Column = SWITCH (
        TRUE (),
         'Table 1'[Product type]  = "A",'Table 1'[Revenue]-  'Table 1'[T Price] ,
         'Table 1'[Product type]  = "B",  'Table 1'[Revenue]  -  'Table 1'[M Price] 
    )

     

     

     

     

3 Replies

  • smpa01's avatar
    smpa01
    Community Champion

    Anonymous  you can write a measure like this

     

    Measure = 
    SWITCH (
        TRUE (),
        MAX ( 'Table 1'[Product type] ) = "A", SUM ( 'Table 1'[Revenue] ) - SUM ( 'Table 1'[T Price] ),
        MAX ( 'Table 1'[Product type] ) = "B", SUM ( 'Table 1'[Revenue] ) - SUM ( 'Table 1'[M Price] )
    )

     

     

     

    or a calculated column

    Column = SWITCH (
        TRUE (),
         'Table 1'[Product type]  = "A",'Table 1'[Revenue]-  'Table 1'[T Price] ,
         'Table 1'[Product type]  = "B",  'Table 1'[Revenue]  -  'Table 1'[M Price] 
    )

     

     

     

     

  • Hi,

    The below is one of ways to create a calculated column.

     

     

    Margin CC =
    IF(
    Data[Product type] = "A" , Data[Revenue] - Data[T Price] ,
    IF ( Data[Product type] = "B" , Data[Revenue] - Data[M Price] ,
    BLANK()
    )
    )
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous,

    Did these suggestions help with your scenario? if that is the case, you can consider Kudo or accept the helpful suggestions to help others who faced similar requirements.

    If these also don't help, please share more detailed information to help us clarify your scenario to test.

    How to Get Your Question Answered Quickly 

    Regards,

    Xiaoxin Sheng