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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rprice3312
Frequent Visitor

Age Categories not working properly - leveling issue?

Hello:

 

My goal is very simple - create "age categories" based on the Age2 measure field so that I can stratify by age groups.  The code below works as indicated by the screenshot below.   However, when I remove the Age2 field, the results are inaccurate as only one category remains which is clearly not correct.  I suspect it's because the DAX expression below needs another statement to level according to the dimension that I want to display the age groups by?  

 

Any advice is appreciated.   I'm very new to writing DAX and apologize if this is very basic.   I have an SSAS Tabular model and am trying to use DAX to create these groups rather than having to build into the model.

 

Regards,,
Rob

 

DAX:

Age Category = SWITCH(TRUE(),

             AND([Age2]>=0, [Age2]<=60),"<60",

             AND([Age2]>60,[Age2]<70),"61-70",

"Older than 70")

 

AgeCatImage.png

1 ACCEPTED SOLUTION
MariaP
Solution Supplier
Solution Supplier

Download Sample PBIX: Age Example

AgesShownByBins.PNGHi, Are you trying to show result as shown?  You can add an index column to your Age table and use your existing DAX to add your Groupings as a new colum.  Results shown above.

View solution in original post

2 REPLIES 2
MariaP
Solution Supplier
Solution Supplier

Download Sample PBIX: Age Example

AgesShownByBins.PNGHi, Are you trying to show result as shown?  You can add an index column to your Age table and use your existing DAX to add your Groupings as a new colum.  Results shown above.

Yes, that's the outcome I'm trying to achieve.  The Tabular Model is not available for me to alter, I have to use a calculated measure to achieve my desired result.  I will try your idea above and I do appreciate your reply.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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