Running count of occurrence in list

vikas_newports

Board Regular
Joined
May 26, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hello
I have more than 50000 records in my sheet and I am using the below formula to count the running occurrence of record
Excel Formula:
=COUNTIF($A$2:A2,A2)

but it hangs my system and takes more than 5 min to run the formula
Is there any way to fast this process?

Prefer option is simple excel, the other option is VBA for solution
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Has your friend entered the formula into the correct column? It would return all 1's if it was entered into C2 instead of B2
 
Upvote 0
@Peter_SSs , yes inputed the formula correctly in B2 cell but I discovered that my friend is testing on the data which is starting with Alphabets. e.g
Code:
ABC1827600046
ABC1827700028
ABC1827800033
ABC1828100001
ABC1828200005
ABC1828200023
instead of
Code:
12
12
13
12
14
12

So it is working if the data is starting with Numerics
 
Upvote 0
data which is starting with Alphabets.
That should make no difference at all.

Are you sure that your friend actually has duplicate vales in the sample data?

vikas_newports.xlsm
AB
1DataCount
2ABC18276000461
3ABC18277000281
4ABC18278000331
5ABC18281000011
6ABC18282000051
7ABC18282000231
8ABC18277000282
9ABC18277000283
10ABC18282000232
Sheet3
Cell Formulas
RangeFormula
B2:B10B2=XLOOKUP(A2,A$1:A1,B$1:B1,0,0,-1)+1
 
Upvote 0
I found this about 10 times faster than either of the formulas using COUNTIF.
I think that there are a lot of variables to be considered with this. I tried the xlookup suggestion with ~45k records, (initial record set of ~5.5k records replicated 8 times with copy & paste, record frequency varied from unique to 200 repetitions in the original data set).

I didn't do exact timing, but from my test.

The original countifs method from post 1 and my alternative both took about 10 seconds.
Vba method was almost instant.
Xlookup took best part of 10 minutes.
 
Upvote 0
I think that I must have a lot more repetitive data than you two & perhaps then the XLOOKUP was finding a match much quicker.
In any case we have already established that the vba solution is very fast and is an acceptable method so let's just stick with that. :)
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,753
Members
449,094
Latest member
dsharae57

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