Conditional Ranking

honkin

Active Member
Joined
Mar 20, 2012
Messages
374
Office Version
  1. 2016
Platform
  1. MacOS
hi

I am having some issues trying to get quite a lot of data ranked correctly. I've done some reading and possibly I need to use COUNTIF rather than RANK.

Here is what I am trying to do.

I have around 140,000 rows of data with the first two columns being date and time. I have numbers in column F and I need to rank the items based on those numbers, but I want the ones with the same date & time to be ranked with the others of the same date and time, if that makes sense. So everything with A being 01/01/2019 and B being 14:45 would be ranked based on the numbers in column F. That would continue right through the sheet, ranking items where A & B match.

Is this possible at all?

Thanks so much in advance
 
Re: Question On Conditional Ranking

Try this starting in G2 on down to breakup ties (presumes any given date-time group is less than 1000 consecutive rows).

=COUNTIFS(A:A,A2,B:B,B2,F:F,"<="&F2)-COUNTIFS(A3:A1000,A2,B3:B1000,B2,F3:F1000,F2)
 
Last edited:
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Re: Question On Conditional Ranking

OK, understood Toadstool

So here are some from the 2018 calendar year file. It's all the same stuff; groups of data where dates are the same and different times. I added the correct ranking manually and sorted them into rank order to make viewing easier.

There is nothing wrong with missing a ranking number, as if there are 3 that rank as 1, then the next number is 4 and not 2. That's a pretty standard ranking convention.

DateTimeNumberRank
31/12/201815:2501
31/12/201815:2562
31/12/201815:2583
31/12/201815:25134
31/12/201815:25145
31/12/201815:25206
31/12/201815:25217
31/12/201815:3031
31/12/201815:3052
31/12/201815:3073
31/12/201815:3094
31/12/201815:3094
31/12/201815:30116
31/12/201815:30116
31/12/201815:30138
31/12/201815:30149
31/12/201815:301610
31/12/201815:301610
31/12/201815:301912
31/12/201815:301912
31/12/201815:302314
31/12/201815:3541
31/12/201815:3541
31/12/201815:3541
31/12/201815:3554
31/12/201815:3585
31/12/201815:3596
31/12/201815:3596
31/12/201815:35108
31/12/201815:35139
31/12/201815:4521
31/12/201815:4552
31/12/201815:4563
31/12/201815:4563
31/12/201815:4575
31/12/201815:4575
31/12/201815:4597
31/12/201815:45148
31/12/201815:45159

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>

I hope that makes it clearer. The dates span all of 2018 and in the 2019 file, it spans all of 2019 to date. There are anywhere from 4 or 5 per group to 20 or so.

cheers
 
Upvote 0
Re: Question On Conditional Ranking

Thanks so much for your reply, AlphaFrog. I actually don't want ties broken up, as that is not the standard ranking convention. Think of it like a horse race or any event where competitors race. If there is a dead head for 1st, the next placing is 3rd, not 2nd; a tie for 3rd and the next placing is 5th and so on. It certainly starts at the correct ranking number now, with the first ranking always being 1, but if we can eliminate the breakup of ties, it will be absolutely perfect.

To your question, yes, the most you'd find in any group is around 20 or so; so maybe I can cap it at 30 for safety. I can always adjust that number

Here is one group I ran it on and you can see it split the three entries which all had a zero where they should all rank as 1. I have sorted them so it is easier to view.

01
02
03
64
75
96
97
98
109
1110
1411
1412
1613
2214
2215

<colgroup><col span="2"></colgroup><tbody>
</tbody>

Thanks so much for your help, AlphaFrog

Try this starting in G2 on down to breakup ties (presumes any given date-time group is less than 1000 consecutive rows).

=COUNTIFS(A:A,A2,B:B,B2,F:F,"<="&F2)-COUNTIFS(A3:A1000,A2,B3:B1000,B2,F3:F1000,F2)
 
Upvote 0
Re: Question On Conditional Ranking

i actually don't want ties broken up, as that is not the standard ranking convention. Think of it like a horse race or any event where competitors race. If there is a dead head for 1st, the next placing is 3rd, not 2nd; a tie for 3rd and the next placing is 5th and so on. It certainly starts at the correct ranking number now, with the first ranking always being 1, but if we can eliminate the breakup of ties, it will be absolutely perfect.

=countifs(a:a,a2,b:b,b2,f:f,"<"&f2)+1
 
Upvote 0
Re: Question On Conditional Ranking

Hi again AlphaFrog

I do have one quick question re this code, if I may. Should it also work on decimal numbers, as I just tried it on a column of numbers with one and two decimal places and everything showed as ranking 1?

cheers
 
Upvote 0
Re: Question On Conditional Ranking

My bad AlphaFrog. I realised late that I had autocalculate turned off. It's a nightmare having it on with 100k+ rows, as once you do anything, it wants to recalc and you're waiting for ages. Once I did a recalculation on the sheet, it picked them up. Sorry for the bother.

cheers
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

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