Forum Discussion
Creating a Column to categorize by quartiles
Hi Everyone!,
I'm new to the forum (and to PowerBI) and I have a question that I have been all day researching for but so far no luck, hope someone can help me!
I have a table of employees, and there is a column with the hourly rate. I would like to add another column to categorize this hourly rates per quartiles, so we have the lower paid quartile, mid lower paid, mid upper paid and upper paid quartiles. I would like it to look like this in the table (can't add screenshots because confidential) :
Hourly rate Quartile
9.55 Q1
10.10 Q1
10.15 Q2
12.10 Q3
13.05 Q4
etc.
I tried calculating the quartiles as measures, with the PERCENTILE.INC function so I have three measures q1, q2 and q3, but then I don't seem to be able to categorize each value from the hourly pay column with those measures...
Sorry if this has been already answered in another thread, I promise I did lots of research and didn't find anything that would work!
Thanks in advanced!
Anonymous , refer if this can help
https://community.powerbi.com/t5/Quick-Measures-Gallery/QUARTILE/td-p/1064307
- Anonymous4 years ago
HI Anonymous,
You can try to use the following measure formula if helps:
Quartile = VAR currRate = MAX ( Table[Hourly rate] ) VAR _min = MINX ( ALLSELECTED ( Table[Hourly rate] ), [Rate] ) VAR _max = MAXX ( ALLSELECTED ( Table[Hourly rate] ), [Rate] ) VAR interval = DIVIDE ( _max - _min, 4 ) VAR result = DIVIDE ( currRate - _min, interval ) RETURN IF ( result > INT ( result ), INT ( result ) + 1, result )Regards,
Xiaoxin Sheng
5 Replies
- amitchandak
Super User
Anonymous , refer if this can help
https://community.powerbi.com/t5/Quick-Measures-Gallery/QUARTILE/td-p/1064307
- speedramps
Super User
Hi Susana
Click here to download example solution
First you need to get the total for all rates:-
All total =CALCULATE(SUM(Facts[Hourly rate]),ALL())Then divide by 4 to get the quartersQuarters =DIVIDE('Dax measures'[All total] , 4 )Then you need to crate a driver table to "drive" your reportQuartileQuartile IDQ1 1 Q2 2 Q3 3 Q4 4 Then create DAX measure to report your QuartilesQuartile rate =VAR Quarters = SELECTEDVALUE(Quartiles[Quartile ID])RETURNQuarters * [Quarters]I am an unpaid Power Bi volunter. Please click the thumbs uo if you like me trying to help you. Also click solved if this fixes your problem. One problem per ticket please. If you need to expand or change your problem them please click solved on this one and raise a new ticket. Thank you.- AnonymousNot applicable
Hi speedramps
Thanks for taking the time this solution, but it is not quite what I am looking for as this is a measure, and what I am looking for is adding a column, i.e. it doesn't say how many lines do I have per quartile. What I am looking for is a way to categorize my employees into four categories, q1, q2, q3, q4, adding that column to my dataset.
Thanks for your help!
- AnonymousNot applicable
HI Anonymous,
You can try to use the following measure formula if helps:
Quartile = VAR currRate = MAX ( Table[Hourly rate] ) VAR _min = MINX ( ALLSELECTED ( Table[Hourly rate] ), [Rate] ) VAR _max = MAXX ( ALLSELECTED ( Table[Hourly rate] ), [Rate] ) VAR interval = DIVIDE ( _max - _min, 4 ) VAR result = DIVIDE ( currRate - _min, interval ) RETURN IF ( result > INT ( result ), INT ( result ) + 1, result )Regards,
Xiaoxin Sheng
- AnonymousNot applicable
Create a New column with the following formula:
Quartile =
IF (
ISBLANK([HOURLY RATE]),
BLANK(),
VAR Rate = [HOURLY RATE]
VAR Q1 = PERCENTILE.INC([HOURLY RATE], 0.25)
VAR Q2 = PERCENTILE.INC([HOURLY RATE], 0.5)
VAR Q3 = PERCENTILE.INC([HOURLY RATE], 0.75)
RETURN
SWITCH (
TRUE(),
Rate <= Q1, "Q1",
Rate <= Q2, "Q2",
Rate <= Q3, "Q3",
"Q4"
)
)