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
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
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.

Top Solution Authors