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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Christianvs
Helper II
Helper II

Getting statistics for quarters of table entries

Hi

 

I have a table with the columns [ID] and [Days] among others:

IDDays
452
574
582
670
827
997
10210
1075


I wish to sort the column with respect to Days (for lowest to highest), make 4 groups (equally sized if possible and else with +-1 entries for one or more of the groups. As long as all entries are accounted for in the 4 groups it doesnt matter which has one entry more or less) and get the minimum, maximum and mean Days for each group. It has to be a DAX measure such that if the data is filtered on some other column(s) the groups will take that into account. I tried a whole lot of different measures using TOPN amongst other functions, but I just haven't been able to make it work correctly.

 

For the above example the sorted list should be:

IDDays
670
452
582
574
1075
827
997
10210

 

and the correct measures should yield:
Group 1 (first 25%): Min=0, Max=2 and Mean=1

Group 2 (from 25% to 50%): Min=2, Max=4 and Mean=3

Group 3 (from 50% to 75%): Min=5, Max=7 and Mean=6

Group 4 (last 25%): Min=7, Max=10 and Mean=8.5


My latest try for the mean of group 2, which don't yield the correct, was:

Q2_Mean_Days = 
VAR Table_days =
    FILTER(
        ALLSELECTED('DB1'),
        NOT ISBLANK('DB1'[Days])
    )
VAR AmountQ2 = [QuarterAmount] // Rounded number that should give a quarter of total entries

VAR Q2_Upper =
    TOPN(
        2 * AmountQ2 ,
        Table_days,
        'DB1'[Days],
        ASC
    )
VAR Q1_Table =
    TOPN(
        AmountQ2 ,
        Table_days,
        'DB1'[Days],
        ASC
    )
VAR Q2_Table =
    EXCEPT(Q2_Upper, Q1_Table)
RETURN
    AVERAGEX(
        Q2_Table,
        'DB1'[Days]
    )

 

Thanks

1 ACCEPTED SOLUTION

@Christianvs , In Window function we can use more than one order by to break ties 

like orderby([Measure], desc, [Brand], asc) 

 

where brand is is column I have used in relation of window  

CALCULATE([Net], WINDOW(1,ABS, 0, REL, ADDCOLUMNS(ALLSELECTED('Item'[Brand])),ORDERBY([net],desc, [Brand], asc)))

Also, consider rownumber with count

% =

Divide(

ROWNUMBER(ALLSELECTED(Item[Brand]),ORDERBY([Net],DESC, [Brand], asc)). calculate(countrows(values(Item[Brand])), allselected()) )

Now this will give % between 0 to 1, which you  can use in a percentile 

 

Use summarize for more than one column with allselected on fact 

Rownumber- https://www.youtube.com/watch?v=yS9-IQjUDwg&list=PLPaNVDMhUXGYo50Ajmr4SgSV9HIQLxc8L&index=1

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Christianvs , You can follow how I have done ABC, by changing % 
Power BI ABC Analysis using Window function, Dynamic Segmentation: https://youtu.be/A8mQND2xSR4

Or quartiles 
https://sqldusty.com/2018/08/31/calculating-quartiles-with-dax-and-power-bi/

https://www.youtube.com/watch?v=U1KdH-2ort8

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

I'm afraid I can't get this working with my problem either 😕

I'm running into some uniqueness problems witht he function WINDOW as the Days column has lots of the same entries. I know for a fact that the highest value og Q1 and the lowest of Q2 should both be 4 days, but I can't get it to correctly show.
It might be that I simply can't get it working using WINDOW but others could

@Christianvs , In Window function we can use more than one order by to break ties 

like orderby([Measure], desc, [Brand], asc) 

 

where brand is is column I have used in relation of window  

CALCULATE([Net], WINDOW(1,ABS, 0, REL, ADDCOLUMNS(ALLSELECTED('Item'[Brand])),ORDERBY([net],desc, [Brand], asc)))

Also, consider rownumber with count

% =

Divide(

ROWNUMBER(ALLSELECTED(Item[Brand]),ORDERBY([Net],DESC, [Brand], asc)). calculate(countrows(values(Item[Brand])), allselected()) )

Now this will give % between 0 to 1, which you  can use in a percentile 

 

Use summarize for more than one column with allselected on fact 

Rownumber- https://www.youtube.com/watch?v=yS9-IQjUDwg&list=PLPaNVDMhUXGYo50Ajmr4SgSV9HIQLxc8L&index=1

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks Amit. Got it working now 🙂

I'll take a look at your youtube, thanks.

 

I've tried with quartiles but the problem is that i need a number (Days) for the first and last entry in a quartile and I haven't been able to get that. But if you have a way of getting the entry position using quartiles I would be very interested in hearing so

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors