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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
achristopherson
Frequent Visitor

Group age by bracket direct query

I have a dataset with names and ages. I need to show three age groups: Under 18, 18-64, 65 and above. Can someone give me some pointers for setting this up? It seems like it should be relatively simple but none of the things I've tried work. I tried creating a conditional column but it won't work in direct query mode. I also tried a DAX formula but it kept giving me an error. 

 

AgeGroups = IF(FamilyMember[Age] < 18, "1) Under 18",If (FamilyMember[Age] <=17 and FamilyMember[Age] >=65),"2)18 -65", If (FamilyMember[Age] >= 65,"3) Over 65",))

 

1 ACCEPTED SOLUTION
v-lionel-msft
Community Support
Community Support

Hi @achristopherson ,

 

You can create a column:

 

Column = 
SWITCH(
    TRUE(),
    FamilyMember[Age] < 18, "1) Under 18",
    FamilyMember[Age] >= 18 && FamilyMember[Age] < 65, "2)18 -65",
    "3) Over 65"
)

 

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-lionel-msft
Community Support
Community Support

Hi @achristopherson ,

 

You can create a column:

 

Column = 
SWITCH(
    TRUE(),
    FamilyMember[Age] < 18, "1) Under 18",
    FamilyMember[Age] >= 18 && FamilyMember[Age] < 65, "2)18 -65",
    "3) Over 65"
)

 

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

Try:

 

AgeGroups = 
  SWITCH(TRUE(),
    FamilyMember[Age] < 18, "1) Under 18",
    FamilyMember[Age] >= 65,"3) Over 65",
    "2)18 -65"
  )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Mariusz
Community Champion
Community Champion

Hi @achristopherson 

 

Try these two patterns.

https://www.daxpatterns.com/dynamic-segmentation/

https://www.daxpatterns.com/static-segmentation/

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

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.