Forum Discussion

KGBOR's avatar
KGBOR
Helper I
3 years ago
Solved

Custom text output based on number values

Hello,   I'm having a rather simple issue but I can't figure it out how to do it in DAX.   I have the lenght of service of employees as a number in years (1 = 12 months, 0.5 = 6 months, 0.25 = 3 ...
  • MAwwad's avatar
    3 years ago

     

    You can use the SWITCH function in DAX to create the categories based on the length of service of employees. Here's an example of how to do it:

     

     
    Service Category = SWITCH( TRUE(), [Length of Service] < 0.25, "0-3 months", [Length of Service] < 1, "3-12 months", [Length of Service] < 2, "1-2 years", [Length of Service] < 5, "2-5 years", [Length of Service] >= 5, "5+ years" )
     

    In the above example, replace [Length of Service] with the name of the column that contains the length of service of employees in years. The SWITCH function evaluates each condition in the order they are listed and returns the corresponding category text if the condition is true. If none of the conditions are true, it returns blank. You can adjust the conditions and category texts to fit your specific intervals.