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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
kevderbeste
Helper III
Helper III

how to get quantile in power bi

Hi everyone, i have a dataset and i need get the decile and quintile of a sales column, in order to put on each'order id' which decile or quintile its belong. 

 

example

 

ORDER ID    DATE             VENTA   QUINTILE
1                 13/01/2020     3000      5
2                 14/02/2020      2500     1


here my pbix https://1drv.ms/u/s!AtEkAF7ffIsqg8Rs7pFT9fzzvkq3cQ?e=iEqGEb

1 ACCEPTED SOLUTION
Anonymous
Not applicable

here the code complete, if you want to do some test:

 

 

let
    id=List.Transform(List.Random(200,1111), each {"a","b","c","d"}{Number.RoundDown( _*4)}),
    sales=List.Transform(List.Random(200,2222), each Number.RoundDown(10+_*500,2)),
    tab=Table.FromColumns({id,sales},{"id","sales"}),
    #"Added Custom" = Table.AddColumn(tab, "QualeDecile", (r)=> Number.IntegerDivide( List.PositionOf(List.Sort(Table.SelectRows(tab, each r[id]=_[id])[sales]),r[sales],null,(x,y)=>x>=y),Number.IntegerDivide(Table.RowCount(Table.SelectRows(tab, each r[id]=_[id])),10))+1),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "pos", (r)=> List.PositionOf(List.Sort(Table.SelectRows(tab, each r[id]=_[id])[sales]),r[sales],null,(x,y)=>x>=y)),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "sizeDec", (r)=> Number.IntegerDivide(Table.RowCount(Table.SelectRows(tab, each r[id]=_[id])),10))
in
    #"Added Custom2"

 

 

I dont know the exact definition of quantile, perhaps the formula for calculating the percentile size should either round up or not at all.

 

View solution in original post

3 REPLIES 3
harshnathani
Community Champion
Community Champion

Hi @kevderbeste ,

 

 

You can  have a look at 

 

https://community.powerbi.com/t5/Desktop/Calculate-percentile-by-group/td-p/478239

https://dash-intel.com/powerbi/statistical_functions_percentile.php

https://www.youtube.com/watch?v=5AxtNdJ5wqk

 


Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

Anonymous
Not applicable

try this:

 

Table.AddColumn(tab, "in which decile I am", (r)=> Number.IntegerDivide( List.PositionOf(List.Sort(Table.SelectRows(tab, each r[id]=_[id])[sales]),r[sales],null,(x,y)=>x>=y),Number.IntegerDivide(Table.RowCount(Table.SelectRows(tab, each r[id]=_[id])),10))+1)

 

this is valid for decile, is easily adptable for any other percentile.

 

I didn't check all the situation at the ends of interval, may be some think needs to be tuned!

 

 

Anonymous
Not applicable

here the code complete, if you want to do some test:

 

 

let
    id=List.Transform(List.Random(200,1111), each {"a","b","c","d"}{Number.RoundDown( _*4)}),
    sales=List.Transform(List.Random(200,2222), each Number.RoundDown(10+_*500,2)),
    tab=Table.FromColumns({id,sales},{"id","sales"}),
    #"Added Custom" = Table.AddColumn(tab, "QualeDecile", (r)=> Number.IntegerDivide( List.PositionOf(List.Sort(Table.SelectRows(tab, each r[id]=_[id])[sales]),r[sales],null,(x,y)=>x>=y),Number.IntegerDivide(Table.RowCount(Table.SelectRows(tab, each r[id]=_[id])),10))+1),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "pos", (r)=> List.PositionOf(List.Sort(Table.SelectRows(tab, each r[id]=_[id])[sales]),r[sales],null,(x,y)=>x>=y)),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "sizeDec", (r)=> Number.IntegerDivide(Table.RowCount(Table.SelectRows(tab, each r[id]=_[id])),10))
in
    #"Added Custom2"

 

 

I dont know the exact definition of quantile, perhaps the formula for calculating the percentile size should either round up or not at all.

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors