Forum Discussion

rprice3312's avatar
rprice3312
Frequent Visitor
8 years ago
Solved

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")

 

  • Download Sample PBIX: Age Example

    Hi, 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.

2 Replies

  • MariaP's avatar
    MariaP
    Icon for Solution Supplier rankSolution Supplier

    Download Sample PBIX: Age Example

    Hi, 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.

    • rprice3312's avatar
      rprice3312
      Frequent Visitor

      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.