Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
KGBOR
Helper I
Helper I

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 months, etc) and as an output I need to create categories for certain intervals as a text. Like people with less than 0.25 years should give me "0-3 months" as a result, between 0.25 and 1 would result in "3-12 months" and so on. What would be the best way to approach it?

 

Thank you!

1 ACCEPTED SOLUTION
MAwwad
Solution Sage
Solution Sage

 

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.

View solution in original post

4 REPLIES 4
MAwwad
Solution Sage
Solution Sage

 

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.

Thank you very much for the detailed answer! Just for my understanding: what does the TRUE operator do in this formula? The rest I understand now but that one is not entirely clear right now. Thank you again!

ryan_mayu
Super User
Super User

@KGBOR 

you can try this

category = SWITCH(TRUE(),'Table'[length of service]<0.25,"0-3 mths",'Table'[length of service]<1,"3-12 mths",">12mths")

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you very much!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.