Formula Help: Count Values within Unique Date Ranges

kkarp

New Member
Joined
Mar 25, 2016
Messages
8
Hello! Long time listener, first time caller.

I have a spreadsheet with rows for observations of individuals. The columns B-D indicate the dates of interest. Each date range in these columns is unique to the individual. The columns (G-L) are calendar dates -- there is a column for every day for 6 months. Individuals have an observation some days, and blanks other days. I want to know the number of observations in a given, unique date range for each individual.


I need help creating a formula that counts the number of values from Date X to Date Y (column E) and from Date X to Date Z (column F). Each row has a unique date range. I have filled out the an approximation of the sheet with what those formulas should return:


ABCDEFGHIJKL
1IDDate XDate YDate Z# Values from Date X to Date Y# Values from Date X to Date Z3/13/23/33/43/53/6
2993/13/33/524lmrslmrqrs
3773/23/43/634rslmrqlm

<tbody>
</tbody>










This spreadsheet will have several thousand individuals, each with unique date ranges, so ideally this formula would be drag-down-able. The codes (lm, rs, etc.) just need to be counted as one instance each.


I have attempted several COUNTIF functions, and have found difficulty since this formula must look at the date columns in the row of the individual as well as the date columns in the column headers. How can I do a matrixed count (if that that even a thing)? I'd be willing to try a VBA solution if folks think that is the best route.


Note:

I realize this might be more easily accomplished if I created a formula to pull down the date from the column header into the rows with the observation codes, like so:


ABCDEFGHIJKL
1IDDate XDate YDate Z# Values from Date X to Date Y# Values from Date X to Date Z3/13/23/33/43/53/6
2993/13/33/5243/13/33/43/53/6
3773/23/43/6343/23/33/43/6

<tbody>
</tbody>









For my column E formula, I could do: (COUNTIF(G3:L3,">="&B3)-COUNTIF(G3:L3,">="&C3))

The issue with this solution is that I really want to avoid adding formulas to practically every cell since this spreadsheet has over 100 columns and several thousand rows.


Cheers, and thanks for any thoughts you might have!
 
I've used the formula that cb366374 corrected a...
Which is identical to the formula I originally posted, adjusted for the extra columns not specifically identified in post #1 and also for the fact that your actual headers are in row 2 with data from row 3, whereas in post #1 you identified headers as row 1 & data from row 2. ;)

Anyway, good to hear it is resolved. Thanks for letting us know. :)
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Anyway, good to hear it is resolved. Thanks for letting us know. :)


No, thank you! Follow-up question -- the formula is working fantastically for me, but I'm having a hard time dissecting exactly what the formula "says". I'm struggling to parse out how the formula is functioning.

Formula:
=COUNTIFS($G$2:$HR$2,">="&$B3,$G$2:$HR$2,"<="&C3,$G3:$HR3)

I tried to translate it (see the nonsensical thing below) and I'm clearly not totally following what's happening here.
=Count if ("Cells in date range", "are greater than or equal to Date X (plus?) Date Range", "are less than or equal to Date Y (plus?) values I want to count")
 
Upvote 0
.. but I'm having a hard time dissecting exactly what the formula "says".

Formula:
=COUNTIFS($G$2:$HR$2,">="&$B3,$G$2:$HR$2,"<="&C3,$G3:$HR3)
That is only part of the formula.

The syntax for COUNTIFS is
COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)
and the function counts how many times all criteria are met.

For your circumstance there are 3 such pairs of range & criteria
=COUNTIFS($G$2:$HR$2,">="&$B3,$G$2:$HR$2,"<="&C3,$G3:$HR3,"<>")

So we count how many times ..

"Cells in date range", "are greater than or equal to Date X"
and
"Cells in date range", "are less than or equal to Date Y"
and
"Cells in the data range", "are not equal to blank"
 
Upvote 0
Wow, thank you for laying that out so clearly! :biggrin: This has been immensely helpful! Peter, you're fantastic! Thanks again for your super speedy and thorough help!
 
Upvote 0

Forum statistics

Threads
1,216,118
Messages
6,128,939
Members
449,480
Latest member
yesitisasport

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