Forum Discussion
Ranking/Grouping based on conditions
Table1
Agent | Duration(s) | Date | Rank |
A | 273 | 01/06/2020 | |
| A | 263 | 01/06/2020 | |
| A | 224 | 01/06/2020 | |
| A | 146 | 02/06/2020 | |
| A | 159 | 03/06/2020 | |
| A | 153 | 04/06/2020 | |
| B | 88 | 01/06/2020 | |
| B | 184 | 02/06/2020 | |
| B | 28 | 02/06/2020 | |
| B | 246 | 02/06/2020 | |
| B | 286 | 03/06/2020 | |
| B | 55 | 04/06/2020 | |
| B | 38 | 04/06/2020 | |
| C | 287 | 02/06/2020 | |
| C | 143 | 02/06/2020 | |
| C | 84 | 02/06/2020 | |
| C | 34 | 02/06/2020 | |
| C | 280 | 03/06/2020 | |
| C | 179 | 04/06/2020 | |
| C | 80 | 05/06/2020 | |
| D | 112 | 01/06/2020 | |
| D | 127 | 01/06/2020 | |
| D | 254 | 01/06/2020 | |
| D | 150 | 02/06/2020 | |
| D | 216 | 03/06/2020 | |
| D | 77 | 04/06/2020 | |
| D | 28 | 05/06/2020 | |
| D | 205 | 06/06/2020 | |
| E | 185 | 01/06/2020 | |
| E | 224 | 01/06/2020 | |
| E | 275 | 01/06/2020 | |
| E | 261 | 02/06/2020 | |
| E | 231 | 03/06/2020 | |
| E | 57 | 04/06/2020 | |
| E | 15 | 05/06/2020 | |
| E | 158 | 05/06/2020 |
I have something similar to the table above. What I need is to split the agents into 4 buckets. The buckets should be ranked from 1 to 4 based on the average of the durations per agent, but only taking the durations before 04/06/2020.
The idea is I want to split the agents into quartiles based on the best to the worst. 1 being the best (shortest avg duration) to 4 (longest average duration).
I can't seem to get the calculations to work. I basically need the Rank column as a calculated column, not a measure as I want the value stored on the table.
Hi Anonymous ,
I directly excluded the rows greater than April 6th when calculating the average.
In addition, you can also change the sorting mechanism, for example, when [__AVG]= Blank() then [__Rank]=0
Best regards,
Lionel ChenIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
6 Replies
- Greg_Deckler
Community Champion
Anonymous - See this: https://community.powerbi.com/t5/Quick-Measures-Gallery/To-Bleep-with-RANKX/m-p/1042520#M452
Also, check out the PERCENTILE.INC, PERCENTILE.EXC and the X equivalents of those functions. They are designed to split things into percentages and you can use them as quartiles.
Also, check out my series on Excel to DAX translation as it has additional information about those functions as well as QUARTILE and PERCENTRANK equivalent for DAX.
https://community.powerbi.com/t5/Community-Blog/P-Q-Excel-to-DAX-Translation/ba-p/1061107
- AnonymousNot applicable
Thanks.
Ive tried using percentile. So I have done it in a few steps
1. Calculated an avg per agent =AVGperAgent= CALCULATE(AVERAGE(table1[duration(s)]),ALLEXCEPT(table1[agent]),table1[date]<DATE(2020,06,22))
2. rank the agents by quartile = Rank =
var low = PERCENTILE.INC(table1[AVGperAgent],.25)
var mid = PERCENTILE.INC(table1[AVGperAgent],.5)
var high = PERCENTILE.INC(table1[AVGperAgent],.75)
RETURN
IF(table1[AVGperAgent]<=low,1,IF(table1[AVGperAgent]<=mid,2,IF(table1[AVGperAgent]<=high,3,IF(table1[AVGperAgent]>high,4,0))))
This should give me an equal distribution of rank counts so very similar counts of each rank, however I'm not getting this. Is there something missing here?- v-lionel-msft
Community Support
Hi Anonymous ,
Is this not what you want?
If yes, please refer to my .pbix file, if not, please show me the expected output value with a table.
Best regards,
Lionel ChenIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.