Forum Discussion

Oros's avatar
Oros
Post Prodigy
4 years ago
Solved

If, else

Hello,

 

I have this 1 table that I would like to create an IF, ELSE column (or a measure) to replace the REGULAR PRICE

 

ITEMREGULAR PRICEDISCOUNTED
BANANA$5 
APPLE$10 
MANGO$20 

 

If discounted=YES, then the price column becomes $1.  If discounted=NO, then regular price.

 

Thanks.

 

5 Replies

  • Hi, Oros 
    as Column 

    IF ( 'Table'[ISDISCOUNTED] = "YES", 1, 'Table'[REGULAR])
  • Hello Oros , 

     

    Add a calculated column-

    NewColumn = IF(Data[DISCOUNTED]="YES",1,Data[REGULAR PRICE])

     

     

    Please mark it as answer if it resolves your issue. Kudos are also appreciated.

     

     

  • Oros's avatar
    Oros
    Post Prodigy

    Hello vojtechsima ,

     

    Thanks for the prompt reply.  I get an error message.  (DAX comparison operations do not support comparing values of type True?False with values of type Text.)

     

    • vojtechsima's avatar
      vojtechsima
      Super User

      Hi, Oros ,
      Make sure your columns are in proper data types, when comparing string ("YES", "NO") the column has to be a text, if numeric values (1,2) it has to be Numeric. PLease check that and try running itagain

      • Oros's avatar
        Oros
        Post Prodigy

        Hello vojtechsima ,

         

        I change it to text but got another error:

         

        "Expressions that yield variant data-type cannot be used to define calculated columns."

         

        Any idea?

         

        Thanks.