Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Creating an IF measure that returns text

Hi I have the following measure that I belive is correct:    Bonus Tier = IF([Bonus Percentage Measure]>=1.05 && [Bonus Percentage Measure]<1.1, "Tier 1", IF([Bonus Percentage Measure]>=1.1 & ...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,

    You need to use double ampersand '&&' between your logical arguments. A single ampersand simply tries to concatenate text.

    I'd also recommend using the SWITCH function in place of your nested IF statements as it makes the code easier to read.

    Below is my table:

    The following DAX might work for you:

     

    Measure = 
        var Bonus_Percentage_Measure = SELECTEDVALUE('Table'[Bonus Percentage Measure])
        var result = 
             SWITCH(
                TRUE(),
                Bonus_Percentage_Measure>=1.05 && Bonus_Percentage_Measure < 1.1 ,"Tier 1",
                Bonus_Percentage_Measure>=1.1 && Bonus_Percentage_Measure < 1.5 , "Tier 2",
                Bonus_Percentage_Measure>=1.5 && Bonus_Percentage_Measure < 2.2 , "Tier 3",
                Bonus_Percentage_Measure >= 2.2 , "Tier 4"
             )
        return result 
    

     

    The final output is shown in the following figure:

     

    Best Regards,

    Xianda Tang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.