Need forumla for sum of duplicate occurance

sanjyou

New Member
Joined
Nov 14, 2018
Messages
15
Need formula to "sum number of duplicate occurance between two dates with one criteria ".
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I setup the following test table:

[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD][/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1/1/2018[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1/31/2018[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]3/2/2018[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]4/1/2018[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]5/1/2018[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]5/31/2018[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]Criterion[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]Count[/TD]
[TD]2[/TD]
[/TR]
</tbody>[/TABLE]

In cell C10 I have the following array formula (requiring the CTRL+SHIFT+ENTER key stroke):

Code:
{ =SUM(IF(D2:D7=D9,1,0)) }

As you can see, it correctly sums the number of duplicate values.

Now, this only works if your data is sorted by date and you're going to select the ranges to calculate. If you want to specify the date ranges and the criterion in separate cells and total the dupes, then here is the approach I took (others might have a more elegant solution):

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1/1/18[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1/31/18[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]3/2/18[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]4/1/18[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]5/1/18[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]5/31/18[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]Start Date[/TD]
[TD]1/1/18[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]End Date[/TD]
[TD]4/1/18[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]Criterion[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]Count[/TD]
[TD]2[/TD]
[/TR]
</tbody>[/TABLE]

The formula in cell B12 is:

Code:
{ =SUMPRODUCT(IF(A1:A6>=B11,1,0),IF(A1:A6<=B12,1,0),IF(B1:B6=B8,1,0)) }

Again, this is an array formula so it requires the CSE keystroke. Also, this is a lot more intuitive if you use range names, E.g., :

Code:
 {=SUMPRODUCT(IF(Date>=StartDate,1,0),IF(Date<=EndDate,1,0),IF(CriterionColumn=Criterion,1,0)) }
 
Last edited:
Upvote 0
Here is a more elegant version of the second formula I posted:

Code:
 { =SUMPRODUCT(--(A1:A6>=B11),--(A1:A6<=B12),--(B1:B6=B8)) }
 
Upvote 0
[1]

{ =SUM(IF(D2:D7=D9,1,0)) }

>>

=COUNTIFS(D2:D7,D9)


[2]

{ =SUMPRODUCT(IF(A1:A6>=B11,1,0),IF(A1:A6<=B12,1,0),IF(B1:B6=B8,1,0)) }

>>

=COUNTIFS(A1:A6,">="&B11,A1:A6,"<="&B12,B1:B6,B8)


[3]

{=SUMPRODUCT(IF(Date>=StartDate,1,0),IF(Date<=EndDate,1,0),IF(CriterionColumn=Criterion,1,0)) }

>>

=COUNTIFS(Date,">="&StartDate,Date,"<="&EndDate,CriterionColumn,Criterion)


[4]

{ =SUMPRODUCT(--(A1:A6>=B11),--(A1:A6<=B12),--(B1:B6=B8)) }

>>

See COUNTIFS of [2].
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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