Finding the sum of the number of times an event occured

ecy61sl

New Member
Joined
Jun 3, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm trying to calculate the total/sum of the number of times an event occurred for a particular ID. For example, in the data sample below, in Column 4 I need to find the total number of times Column 3 is equal to 1 for a particular driverid from Column 1.

I've tried using various combinations of countifs and vlookup but was unsuccessful. Any solutions? TIA!

driverid​
distance​
ITC Flag​
Total ITC by Driver​
27029​
0.88​
0​
27029​
4.85​
1​
27029​
5​
0​
27029​
3.82​
0​
27029​
1.83​
1​
27029​
3.88​
0​
27029​
0.06​
1​
34295​
1.6​
0​
34295​
6.84​
0​
34295​
1.6​
1​
34295​
3.31​
1​
34295​
6.84​
1​
34295​
5.1​
0​
53863​
3.15​
0​
53863​
5.17​
0​
53863​
2.47​
1​
53863​
5.62​
0​
53863​
6.09​
0​
53863​
0.99​
1​
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Something like this?
Book1
ABCD
1driveriddistanceITC FlagTotal ITC by Driver
2270290.8804
3270294.8513
42702950 
5270293.820 
6270291.831 
7270293.880 
8270290.061 
9342951.603
10342956.840 
11342951.613
12342953.311 
13342956.841 
14342955.10 
15538633.1504
16538635.170 
17538632.4712
18538635.620 
19538636.090 
20538630.991 
Sheet1
Cell Formulas
RangeFormula
D2:D20D2=IF(COUNTIFS($A$2:A2,A2,$C$2:$C2,C2)=1,COUNTIFS($A$2:$A$20,A2,$C$2:$C$20,C2),"")
 
Upvote 0
Hi AhoyNC,

Thanks for the reply. The output I need is attached below. Hope my question is clearer now.

ITC Trips till 12.05 (version 1).xlsb
ABCD
1driveriddistanceITC FlagTotal ITC by Driver
2270290.8803
3270294.8513
427029503
5270293.8203
6270291.8313
7270293.8803
8270290.0613
9342951.603
10342956.8403
11342951.613
12342953.3113
13342956.8413
14342955.103
15538633.1502
16538635.1702
17538632.4712
18538635.6202
19538636.0902
20538630.9912
Sheet3
 
Upvote 0
Welcome to the MrExcel board!

I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

See if this is what you want.

20 06 04.xlsm
ABCD
1driveriddistanceITC FlagTotal ITC by Driver
2270290.8803
3270294.8513
427029503
5270293.8203
6270291.8313
7270293.8803
8270290.0613
9342951.603
10342956.8403
11342951.613
12342953.3113
13342956.8413
14342955.103
15538633.1502
16538635.1702
17538632.4712
18538635.6202
19538636.0902
20538630.9912
Countifs
Cell Formulas
RangeFormula
D2:D20D2=COUNTIFS(A$2:A$20,A2,C$2:C$20,1)
 
Upvote 0
Hey Peter_SSs,

That works perfectly ? except I have 180k+ lines of data.

Do let me know if there's a faster way to do this. Read somewhere else about doing a concat first but that takes almost the same amount of time as well.

Thanks!
 
Upvote 0
If your ver. of Excel 365 has the FILTER function - Try:
Book1
ABCD
1driveriddistanceITC FlagTotal ITC by Driver
2270290.8803
3270294.8513
427029503
5270293.8203
6270291.8313
7270293.8803
8270290.0613
9342951.603
10342956.8403
11342951.613
12342953.3113
13342956.8413
14342955.103
15538633.1502
16538635.1702
17538632.4712
18538635.6202
19538636.0902
20538630.9912
Sheet1
Cell Formulas
RangeFormula
D2:D20D2=ROWS(FILTER($C$2:$C$20,($A$2:$A$20=A2)*($C$2:$C$20=1)))
 
Upvote 0
Thanks for updating your profile. (y)


except I have 180k+ lines of data.
Yes, that would make the COUNTIFS almost impossible to wait for. :)

I think you will find the FILTER method similarly slow (if you have that function)

If you must use formulas, then something like this would be a reasonable amount faster, but still may be too slow.
=IF(A2=A1,E1,COUNTIFS(A$2:A$185000,A2,C$2:C$185000,1))


If you don't need the results to be dynamic then this macro processed 185,000 rows for me in less than 1 second.
I have assumed that ITC Flag is always 0 or 1

VBA Code:
Sub Count_Ones()
  Dim a As Variant
  Dim d As Object
  Dim i As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  a = Range("A2", Range("C" & Rows.Count).End(xlUp)).Value
  For i = 1 To UBound(a)
    d(a(i, 1)) = d(a(i, 1)) + a(i, 3)
  Next i
  For i = 1 To UBound(a)
    a(i, 1) = d(a(i, 1))
  Next i
  Range("D2").Resize(UBound(a)).Value = a
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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