Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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!
Solved! Go to Solution.
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:
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.
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:
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!
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")
Proud to be a Super User!
Thank you very much!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
61 | |
52 | |
50 | |
36 | |
33 |
User | Count |
---|---|
84 | |
71 | |
55 | |
45 | |
43 |