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
Sid10
Helper I
Helper I

Calculating Percentiles in PowerBI

In Excel, we can use percentrank.inc function to calculate the percentile scores for a list of values. How do I accomplish the same in powerbi? So, for illustration, say, I have a set of 7 values - For each value I want to know what is its percentile score. I hope to then put each value in different quartiles.

Sid10_0-1599075732268.png

I was able to calculate the 'rank', if that helps.  

Rank = RANKX(ALL('Table'),CALCULATE(SUM('Table'[Value])))

 

1 ACCEPTED SOLUTION
Tahreem24
Super User
Super User

Try this DAX:

 

Percentile = RANKX ( ALL ( TableName ), CALCULATE ( SUM ( TableName[Value] ) ), , ASC, SKIP ) / COUNTX ( ALL ( TableName ), TableName[Value] )

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@Sid10 According to Excel to DAX Translation: https://community.powerbi.com/t5/Community-Blog/Excel-to-DAX-Translation/ba-p/1060991

https://community.powerbi.com/t5/Community-Blog/P-Q-Excel-to-DAX-Translation/ba-p/1061107

PERCENTRANK Equivalent is here:

https://community.powerbi.com/t5/Quick-Measures-Gallery/PERCENTILERANK/td-p/1082573

and kind of looks like this:

PERCENTILERANK.INC = 
    VAR __Value = MAX('RanksInc'[Rank])
RETURN
    IF(
        __Value IN SELECTCOLUMNS('ValuesInc',"Values",[Value]),
                VAR __NumLower = COUNTROWS(FILTER('ValuesInc',[Value] < __Value))
                VAR __NumHigher = COUNTROWS(FILTER('ValuesInc',[Value] > __Value))
                VAR __Rank = __NumLower / (__NumLower + __NumHigher)
            RETURN IF(ISBLANK(__Rank),0,__Rank),
                VAR __Lower = MAXX(FILTER('ValuesInc',[Value] < __Value),[Value])
                VAR __Higher = MINX(FILTER('ValuesInc',[Value] > __Value),[Value])
                VAR __LowerNumLower = COUNTROWS(FILTER('ValuesInc',[Value] < __Lower))
                VAR __LowerNumHigher = COUNTROWS(FILTER('ValuesInc',[Value] > __Lower))
                VAR __LowerRank = __LowerNumLower / (__LowerNumLower + __LowerNumHigher)
                VAR __HigherNumLower = COUNTROWS(FILTER('ValuesInc',[Value] < __Higher))
                VAR __HigherNumHigher = COUNTROWS(FILTER('ValuesInc',[Value] > __Higher))
                VAR __HigherRank = __HigherNumLower / (__HigherNumLower + __HigherNumHigher)
            RETURN
                __LowerRank + ( __Value - __Lower ) / (__Higher - __Lower ) * ( __HigherRank - __LowerRank )
    )

 

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Tahreem24
Super User
Super User

Try this DAX:

 

Percentile = RANKX ( ALL ( TableName ), CALCULATE ( SUM ( TableName[Value] ) ), , ASC, SKIP ) / COUNTX ( ALL ( TableName ), TableName[Value] )

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

@Tahreem24 Thank you for that elegant solution to get to percentiles using a simple Rank and Count function!

There is a small error in your formula though. Percentile = R/(n+1) [In other words you need to add 1 to the denominator]. Please edit your answer so others are not misguided on this. 

Sid10_0-1602800893256.jpeg

 

hi  @Sid10 

Just adjust the rank measure as below:

Rank 1 = RANKX(ALL('Table'[Name]),CALCULATE(SUM('Table'[Value])))

or

Rank 2 = RANKX(ALLSELECTED('Table'[Name]),CALCULATE(SUM('Table'[Value])))

Result:

1.JPG

 

Regards,

Lin

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

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.