Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

IF Statement using Text Column

Hello, 

I want to use an IF Statement on a text column to return certain values/calculations from another column.

 

For example, 

If Column 'Name' = "New" then Calculate(Total_Value*12) else (Total_Value)

 

I haven't been able to figure out how to do this.

I tried this but get an error for Max function only accepts a column reference as an argument

Value = IF(MAX('Value Table'[Name]="New"),[Total_Value*12],[Total Value])
 
Any help would be greatly appreciated.
  • Anonymous , It would be like this:-

    Value =
    SWITCH (
        TRUE (),
        MAX ( 'Value Table'[Name] ) = "New", [Total_Value] * 12,
        MAX ( 'Value Table'[Name] ) = "Old", [Total_Value] / 12,
        [Total Value]
    )

4 Replies

  • Samarth_18's avatar
    Samarth_18
    Community Champion

    Hi Anonymous ,

     

    Ideal code what your trying would be like this:-

    Value = IF(MAX('Value Table'[Name])="New",[Total_Value]*12,[Total Value])

    I am considering [Total_value] as some already created measure.

     

    Thanks,

    Samarth

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Samarth_18 

       

      Thank you for this, it works perfectly!

      One further question if that is ok... is it also possible to have two IF statements in this Measure?

       

      For example -

      If Column 'Name' = "New" then Calculate(Total_Value*12)

      or

      If Column 'Name' = "Old" then Calculate(Total_Value/12)

      else (Total_Value)

       

      Thank you for your speedy reply and help 🙂

      • Samarth_18's avatar
        Samarth_18
        Community Champion

        Anonymous , It would be like this:-

        Value =
        SWITCH (
            TRUE (),
            MAX ( 'Value Table'[Name] ) = "New", [Total_Value] * 12,
            MAX ( 'Value Table'[Name] ) = "Old", [Total_Value] / 12,
            [Total Value]
        )