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
Chenxu
New Member

How to get Percentiles with group by

I have a table with 3 columns: UserName, StartDate, Duration. I want to get the percentiles of Duration for each user on each day. How to write the query?

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

Hi Chenxu,

 

For test, I have made a sample table like this:

 7.PNG

To get the percentiles of Duration for each user on each day, you can create a calculate column and use DAX formula below:

Percentile =

VAR Duration_Sum =

SWITCH(Table1[UserName],

    "A", CALCULATE(SUM(Table1[Duration]), FILTER(Table1, Table1[UserName] = "A")),

    "B", CALCULATE(SUM(Table1[Duration]), FILTER(Table1, Table1[UserName] = "B")),

    "C", CALCULATE(SUM(Table1[Duration]), FILTER(Table1, Table1[UserName] = "C")))

RETURN

CALCULATE(DIVIDE(MAX(Table1[Duration]), Duration_SUm), FILTER(Table1, Table1[UserName] = EARLIER(Table1[UserName]) && Table1[StartDate] = EARLIER(Table1[StartDate])))

 

The result is like below:

 6.PNG

 

Sample PBIX here:

https://www.dropbox.com/s/sb5v6zpbq1kjlc5/For%20Chenxu.pbix?dl=0

 

Regards,

Jimmy Tao

View solution in original post

1 REPLY 1
v-yuta-msft
Community Support
Community Support

Hi Chenxu,

 

For test, I have made a sample table like this:

 7.PNG

To get the percentiles of Duration for each user on each day, you can create a calculate column and use DAX formula below:

Percentile =

VAR Duration_Sum =

SWITCH(Table1[UserName],

    "A", CALCULATE(SUM(Table1[Duration]), FILTER(Table1, Table1[UserName] = "A")),

    "B", CALCULATE(SUM(Table1[Duration]), FILTER(Table1, Table1[UserName] = "B")),

    "C", CALCULATE(SUM(Table1[Duration]), FILTER(Table1, Table1[UserName] = "C")))

RETURN

CALCULATE(DIVIDE(MAX(Table1[Duration]), Duration_SUm), FILTER(Table1, Table1[UserName] = EARLIER(Table1[UserName]) && Table1[StartDate] = EARLIER(Table1[StartDate])))

 

The result is like below:

 6.PNG

 

Sample PBIX here:

https://www.dropbox.com/s/sb5v6zpbq1kjlc5/For%20Chenxu.pbix?dl=0

 

Regards,

Jimmy Tao

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.