Forum Discussion
Ranking with multiple columns
- 4 years ago
Hi, Anonymous
Measures:
_Super Region Ranking = IF([_Total Services]<=0,0,RANKX(FILTER(ALL('Table2'),'Table2'[ Super Region ]=MAX('Table2'[ Super Region ])&&[_Total Services]>0),[_Total Services],,DESC,Dense))_Region Ranking = IF([_Total Services]<=0,0,RANKX(FILTER(ALL('Table2'),'Table2'[Region ]=MAX('Table2'[Region ])&&[_Total Services]>0),[_Total Services],,DESC,Dense))_Total Services = SUM('Table2'[ Security Total ])Result:
Please refer to the attachment below for details. Hope this helps.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - 4 years ago
Hi, Anonymous
The max function here is used to get the value of the current row. In the current row context, since there is only one row, no matter you use the MAX, MIN, or SELECTEDVALUE functions, it has the same effect.
Now to explain the above formula, first we look at the syntax of the RANKX function:So
_Super Region Ranking = IF( [_Total Services] <= 0, 0, RANKX( FILTER( ALL( 'Table2' ), 'Table2'[ Super Region ] = MAX( 'Table2'[ Super Region ] ) && [_Total Services] > 0 ), //Get all records in the same region and rank them in a sub-table of all rows in this same region. //Filter the sub-tables whose region in the entire table is equal to the region of the current row. [_Total Services], , DESC, DENSE ) )Hope this helps you understand.
Best Regards,
Community Support Team _ Zeon ZhengIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for your reply. I need ranking by " security total" . Below is the sample data with results in bold columns. Yes region is a subset for super region and it is ranking within each region. Kindly note that this is just a sample. The actual data is not like this i.e here each super region has four rows only but in acual data it is not fixed(East has 20 rows, south 50 rows etc), same goes for region, here region ranking is 1-2 but in actual data VA occurs 10 times so its ranking is 1-10. Also for -ve and 0 values in " security total", rank is 0. I was able to achieve Salesrep ranking with -
| Region | Super Region | President | Sales Director | Super Region Ranking | Region Ranking | SalesEep Ranking | SalesRep Name | Security Total | total Spend | % Security Spend |
| CA | West | A3 | Tan | 3 | 1 | 5 | Rob | 306,614 | 10,937 | 8% |
| CA | West | A3 | Tan | 4 | 2 | 6 | Emma | 246,627 | 10,937 | 5486% |
| FL | South | A6 | Med | 2 | 1 | 8 | Charlotte | 126,653 | 779,857 | 1% |
| FL | South | A6 | Med | 4 | 2 | 10 | Jose | 6,679 | 779,857 | 1% |
| GA | South | A10 | Ryan | 1 | 1 | 7 | Mia | 186,640 | 779,857 | 1% |
| GA | South | A10 | Ryan | 3 | 2 | 9 | Sam | 66,666 | 779,857 | 1% |
| MD | East | A2 | Mill | 2 | 1 | 2 | Sophia | 800,000 | 212,853 | 376% |
| MD | East | A2 | Mill | 3 | 2 | 13 | Dave | 289 | 212,853 | 0% |
| NYC | North | A4 | Bro | 2 | 1 | 12 | John | 1,633 | 484,674 | 0% |
| NYC | North | A4 | Bro | 0 | 0 | 0 | Ava | (3,100) | 484,674 | 0% |
| PA | North | A9 | Brown | 1 | 1 | 11 | Isabella | 4,000 | 484,674 | 1% |
| PA | North | A9 | Brown | 0 | 0 | Kevin | (734) | 484,674 | 0% | |
| TX | West | A8 | Tand | 1 | 1 | 3 | Amelia | 426,588 | 10,937 | 8% |
| TX | West | A8 | Tand | 2 | 2 | 4 | Ram | 366,601 | 10,937 | 8% |
| VA | East | A1 | Mil | 1 | 1 | 1 | Olivia | 3,000,000 | 212,853 | 1409% |
| VA | East | A1 | Mil | 4 | 2 | 14 | Nick | 287 | 212,853 | 0% |