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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Age Profile - Direct Query

It would be really great if someone could help me with this.

 

I'm querying my DB directly and I'm trying to group open transactions into an age range. I've created a calculated column which gives me the age in days, now I want to group the results:

 

0-5 Days

6-20 Days

21-50 Days

>50 Days

 

It would also be useful if I could order the results so it always shows in the order above.

 

Capture.PNG

1 ACCEPTED SOLUTION
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

 

If I understand you correctly, you should be able to use the formula below to add another calculate column to group the ages into range.

Range =
SWITCH (
    TRUE (),
    'Table1'[Age] >= 0
        && 'Table1'[Age] <= 5, "0-5 Days",
    'Table1'[Age] >= 6
        && 'Table1'[Age] <= 20, "6-20 Days",
    'Table1'[Age] >= 21
        && 'Table1'[Age] <= 50, "21-50 Days",
    'Table1'[Age] > 50, ">50 Days",
    ""
)

It would also be useful if I could order the results so it always shows in the order above.

 


As you're using Direct Query mode, you may need to firstly add a new table called "Age Range" like below on your datasource side.

 

Range Index
0-5 Days 1
6-20 Days 2
21-50 Days 3
>50 Days 4

 

And sort the Range column by the Index column with Sort by Column option on Power BI Desktop.

 

sort.PNG

 

Then you should be able to create a relationship between "Age Range" table and your data table with the "Range" column, and show the Range column on your report(which should be ordered correctly).

 

Regards

View solution in original post

2 REPLIES 2
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

 

If I understand you correctly, you should be able to use the formula below to add another calculate column to group the ages into range.

Range =
SWITCH (
    TRUE (),
    'Table1'[Age] >= 0
        && 'Table1'[Age] <= 5, "0-5 Days",
    'Table1'[Age] >= 6
        && 'Table1'[Age] <= 20, "6-20 Days",
    'Table1'[Age] >= 21
        && 'Table1'[Age] <= 50, "21-50 Days",
    'Table1'[Age] > 50, ">50 Days",
    ""
)

It would also be useful if I could order the results so it always shows in the order above.

 


As you're using Direct Query mode, you may need to firstly add a new table called "Age Range" like below on your datasource side.

 

Range Index
0-5 Days 1
6-20 Days 2
21-50 Days 3
>50 Days 4

 

And sort the Range column by the Index column with Sort by Column option on Power BI Desktop.

 

sort.PNG

 

Then you should be able to create a relationship between "Age Range" table and your data table with the "Range" column, and show the Range column on your report(which should be ordered correctly).

 

Regards

Anonymous
Not applicable

Anyone?

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.