Rank Function

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,134
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I tried a lot but not sure as what it the problem, the function is not giving me the correct output, in column AQ, any way to fix it.

Book1
AMANAOAPAQAR
5Actual Rank
6Row LabelsCount of PHONE_NUMRankshould Be
7RIYADH_Tuwaiq_TWIQRDJ113V1311
8RIYADH_Al Yarmuk_YRMKRDJ11521122
9RIYADH_Al Munsiyah_MUNSRDJ1192533
10RIYADH_Qurtubah_KRTBRDJ1250544
11(blank)5 
12RIYADH_Al Munsiyah_MUNSRDJ1223465
13RIYADH_Al Yarmuk_YRMKRDJ118D476
14RIYADH_Al Rabeea_RABERDJ1294487
15RIYADH_Al Nadhim_NDIMRDJ003939
16RIYADH_Ghirnatah_GRNTRDJ114E310
17RIYADH_Qurtubah_KRTBRDJ1257311
18RIYADH_Al Munsiyah_MUNSRDJ1232312
19RIYADH_Huteen_HTYNRDJ1124313
20RIYADH_Al Murabba_MURBRDJ128R314
21RIYADH_Al Qadisiyah_QADSRDJ1113315
22RIYADH_Tuwaiq_TWIQRDJ113G216
23RIYADH_Ishbiliyyah_SPELRDJ127B217
24RIYADH_Al Muruj_MRUJRDJ1185218
25RIYADH_Yasmeen_YSMNRDJ1125219
26RIYADH_Ishbiliyyah_SPELRDJ127D220
27RIYADH_Al Mughrizat_MGRZRDJ123H221
28RIYADH_Al Falah_FLAHRDJ1124222
29RIYADH_Tuwaiq_TWIQRDJ114S223
30RIYADH_Yasmeen_YSMNRDJ11C6224
31RIYADH_Yasmeen_YSMNRDJ1126225
32RIYADH_Al Malqa_MLGARDJ151C226
33RIYADH_Ar Rayyan_RYANRDJ115H227
34RIYADH_Al Ezdehar_ZDHRRDJ113D228
35RIYADH_Qurtubah_KRTBRDJ0013129
36RIYADH_Al Masani_MSNERDJ1182130
37RIYADH_Al Amal_AMELRDJ000D131
38RIYADH_Al Ezdehar_ZDHRRDJ113N132
39RIYADH_IRQAH_ERQARDJ12Z1133
40RIYADH_Al Qirawan_GYRNRDJ1527134
41MAKKAH_AL UMRAH AL JADIDAH_UMRNKHJ023N135
42RIYADH_Al Rabeea_RABERDJ1291136
43RIYADH_Al Nadhim_NDIMRDJ114U137
44JEDDAH_AL SALAMEH_SLMHKHJ11F9138
45RIYADH_Huteen_HTYNRDJ1123139
46RIYADH_Al Rimayah_RMYARDJ113C140
47RIYADH_Al Munsiyah_MUNSRDJ1190141
48RIYADH_Al Shohada_SHHDRDJ002O142
49RIYADH_Qurtubah_KRTBRDJ1251143
50RIYADH_Al Wahah_WAHARDJ1119144
51RIYADH_Tuwaiq_TWIQRDJ1142145
52TABUK_AL RABIEA_RBEATBJ0007146
53RIYADH_Yasmeen_YSMNRDJ1128147
54JEDDAH_AL RUGHAMAH_RGMAKHJ140M148
55RIYADH_Dherat Al Laben_ZHRHRDJ1133149
56ABHA_Al Badea_BADERRJ000W150
57RIYADH_Ghirnatah_GRNTRDJ114M151
58RIYADH_Al Yarmuk_YRMKRDJ118C152
59KHAMIS MUSHAYT_Al Jameiyine_KMISRRJ183C153
60RIYADH_Al Janadriyah_JNADRDJ0018154
61RIYADH_Al Munsiyah_MUNSRDJ0000155
62RIYADH_Al Yarmuk_YRMKRDJ119D156
63RIYADH_Ishbiliyyah_SPELRDJ127W157
64RIYADH_Al Yarmuk_YRMKRDJ119O158
65JEDDAH_AL MANAR_MNARKHJ001T159
66RIYADH_An Nakhil_NKELRDJ1390160
67JEDDAH_AJAWED_JAWDKHJ000V161
68RIYADH_An Narjis_NRJSRDJ11BM162
69AL QURAYYAT_AL FAISALIAH_FISLJFJ00C5163
70RIYADH_An Nuzhah_NZHARDJ117D164
71RIYADH_Ad Dar Al Baida_ADDRRDJ1153165
72JIZAN_ISKAN KING ABDULLAH FOR REFUGEE_RWENJZJ0000166
73RIYADH_Al Aqiq_AQEQRDJ1137167
74RIYADH_As Sahafah_SHAFRDJ115G168
75RIYADH_Al Ezdehar_ZDHRRDJ113G169
76RIYADH_Dherat Al Laben_DLBNRDJ0101170
77RIYADH_Dherat Al Laben_DLBNRDJ0116171
78RIYADH_-_ZDHRRDJ113D172
79DAMMAM_Al Fayhaa_FIHAEAJ11D5173
80KHAMIS MUSHAYT_Thelalah_ZETNRRJ0000174
81JEDDAH_AL YAQOOT_YAQTKHJ001L175
82RIYADH_Al Yarmuk_YRMKRDJ1182176
83RIYADH_Al Yarmuk_YRMKRDJ1184177
84Grand Total147 
Sheet1
Cell Formulas
RangeFormula
AQ7:AQ84AQ7=IFERROR(IF(OR(AM7="#N/A",AM7="Grand Total",AM7="(blank)"),"",RANK(AN7,$AN$7:$AN$500000,0)+COUNTIF($AN$7:AN7,AN7)-2),"")
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
The problem is not with the RANK but rather with the numbers you are ranking, in column AN. In your formula in column AQ you are instructing it to put a blank ("") if the value in AM is "(blank)", and it is doing it correctly, but the false part of the formula when the rank is calculated is still based on the entire set of values in column AN. As a test if you delete the 5 in AN11 you will find that your RANK formula works perfectly.
I don't know how you are generating the values for Count of PHONE_NUM in column AN, but if it's a formula then I would include the condition there, and then in column AQ just use a simple rank formula.
For example, in column AN:
Excel Formula:
=IF(OR(AM7="#N/A",AM7="Grand Total",AM7="(blank)"),0,COUNT(....)
or you might instead be able to use a COUNTIFS formula.
 
Upvote 0
Hello, your might try:

Excel Formula:
=IFERROR(IF(OR(AM7="#N/A",AM7="Grand Total",AM7="(blank)"),"",COUNTIFS($AM$7:$AM$84,"<>"&"Grand Total",$AM$7:$AM$84,"<>"&"(blank)",$AM$7:$AM$84,"<>"&"#N/A",$AN$7:$AN$84,">"&AN7))+COUNTIF($AN$7:AN7,AN7),"")

or (as it seems that you are more interested in a sequence of sorted data)

Excel Formula:
=LET(
a,AM7:AM84,
IF((a<>"(blank)")*(a<>"#N/A")*(a<>"Grand Total"),SCAN(0,a,LAMBDA(a,b,IF(b="(blank)",a,a+1))),""))
 
Upvote 0
Solution
The problem is not with the RANK but rather with the numbers you are ranking, in column AN. In your formula in column AQ you are instructing it to put a blank ("") if the value in AM is "(blank)", and it is doing it correctly, but the false part of the formula when the rank is calculated is still based on the entire set of values in column AN. As a test if you delete the 5 in AN11 you will find that your RANK formula works perfectly.
I don't know how you are generating the values for Count of PHONE_NUM in column AN, but if it's a formula then I would include the condition there, and then in column AQ just use a simple rank formula.
For example, in column AN:
Excel Formula:
=IF(OR(AM7="#N/A",AM7="Grand Total",AM7="(blank)"),0,COUNT(....)
or you might instead be able to use a COUNTIFS formula.
ok if instead of "" i change it to 0, still the output is not correct.

in this case the output is 1,2,3,4,0,6 instead of 1,2,3,4,5 and so on....
 
Upvote 0
Hello, your might try:

Excel Formula:
=IFERROR(IF(OR(AM7="#N/A",AM7="Grand Total",AM7="(blank)"),"",COUNTIFS($AM$7:$AM$84,"<>"&"Grand Total",$AM$7:$AM$84,"<>"&"(blank)",$AM$7:$AM$84,"<>"&"#N/A",$AN$7:$AN$84,">"&AN7))+COUNTIF($AN$7:AN7,AN7),"")

or (as it seems that you are more interested in a sequence of sorted data)

Excel Formula:
=LET(
a,AM7:AM84,
IF((a<>"(blank)")*(a<>"#N/A")*(a<>"Grand Total"),SCAN(0,a,LAMBDA(a,b,IF(b="(blank)",a,a+1))),""))
this is perfect, thanks a lot
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,127
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top