COUNT num of unique IDs in date range with other conditions

BradleyS

Active Member
Joined
Oct 28, 2006
Messages
333
Office Version
  1. 2010
Platform
  1. Windows
Excel 2010
I'm struggling to get the correct count of unique IDs in a date range from a table, that includes additional criteria as shown below.
The formula works without the REASON and SOURCE added to the formula, but I need these to define the correct counts.

These are my 2 formulas using Ctrl+Shift+Enter that aren't working:
=SUMPRODUCT(IF((EVENTDATE<=$G$2)*(EVENTDATE>=$F$2), COUNTIFS(EVENTDATE, "<="&$G$2, EVENTDATE, ">="&$F$2, ID, ID,REASON,"Special Risk",SOURCE, "In House"), 0))
=SUMPRODUCT(IF((EVENTDATE<=$G$2)*(EVENTDATE>=$F$2), COUNTIFS(EVENTDATE, "<="&$G$2, EVENTDATE, ">="&$F$2, ID, ID,REASON,"Routine",SOURCE, "In House"), 0))

It is using DNRs of each column header starting from row 2 to row12.
The date range must be within the period shown in F1 and G1. I have shown the dates in the table in red that should not be counted.
The count should show as 2 for both formulas, but is showing as 5 and 7.
What am I doing wrong?
COUNTIDS.jpg
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try this:

Book1
ABCDEFG
1IDEvent DateReasonSourceStart DateEnd Date
2157645/26/2022Special RiskIn House5/26/20215/26/2022
3157645/26/2022Special RiskIn House
4157817/15/2021Special RiskIn House
5157818/17/2005RoutineIn House
6157813/26/2009Special RiskOutsideRequired Result
7157813/26/2008RoutineOutside2
8223806/15/2021RoutineIn House2
9223806/15/2020RoutineIn House
102344210/27/2021RoutineIn House
112344210/29/2021RoutineOutside
122344210/29/2021RoutineIn House
Sheet4
Cell Formulas
RangeFormula
E7E7=SUMPRODUCT(SIGN(FREQUENCY(IF(($B$2:$B$12>=$F$2)*($B$2:$B$12<=$G$2)*($C$2:$C$12="Special Risk")*($D$2:$D$12="In House"),$A$2:$A$12),ROW(INDIRECT(MIN($A$2:$A$12)&":"&MAX($A$2:$A$12))))))
E8E8=SUMPRODUCT(SIGN(FREQUENCY(IF(($B$2:$B$12>=$F$2)*($B$2:$B$12<=$G$2)*($C$2:$C$12="Routine")*($D$2:$D$12="In House"),$A$2:$A$12),ROW(INDIRECT(MIN($A$2:$A$12)&":"&MAX($A$2:$A$12))))))


This assumes the IDs are all numeric under 1,000,000, but it can be adapted if that's not true.
 
Upvote 0
Solution
Well there is no doubt that this works, so thank you very much.
However, I'm going to have to take a hard look at how you have done this as it is using a few things I have never used before i.e. SIGN, and INDIRECT.
Thank you for all your help.
 
Upvote 0
Usually FREQUENCY is the unfamiliar one. Let me know if you have questions.

Anyway, glad I could help! Thanks for the feedback. 😎
 
Upvote 0

Forum statistics

Threads
1,214,411
Messages
6,119,360
Members
448,888
Latest member
Arle8907

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