Count days date range within 12 date ranges

strooman

Active Member
Joined
Oct 29, 2013
Messages
333
Office Version
  1. 2016
Platform
  1. Windows
How many days of a given date range in C2:D2, fall within multiple date ranges in columns A2:B13?
I'm interested in formulas in column E2:E13 (count per period) and F2 (total count). I typed in the desired results in Green.

Help is much appreciated.

[TABLE="class: grid, width: 700"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD]Start_Of_Month[/TD]
[TD]End_Of_Month[/TD]
[TD]Start[/TD]
[TD]End[/TD]
[TD]Count[/TD]
[TD]Total_Count[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: right"]1-1-2014[/TD]
[TD="align: right"]31-1-2014[/TD]
[TD="align: right"]15-3-2014[/TD]
[TD="align: right"]27-7-2014[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]133[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: right"]1-2-2014[/TD]
[TD="align: right"]28-2-2014[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD="align: right"]1-3-2014[/TD]
[TD="align: right"]31-3-2014[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]16[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD="align: right"]1-4-2014[/TD]
[TD="align: right"]30-4-2014[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]30[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]6[/TD]
[TD="align: right"]1-5-2014[/TD]
[TD="align: right"]31-5-2014[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]31[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]7[/TD]
[TD="align: right"]1-6-2014[/TD]
[TD="align: right"]30-6-2014[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]30[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]8[/TD]
[TD="align: right"]1-7-2014[/TD]
[TD="align: right"]31-7-2014[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]26[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]9[/TD]
[TD="align: right"]1-8-2014[/TD]
[TD="align: right"]31-8-2014[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]10[/TD]
[TD="align: right"]1-9-2014[/TD]
[TD="align: right"]30-9-2014[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]11[/TD]
[TD="align: right"]1-10-2014[/TD]
[TD="align: right"]31-10-2014[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]12[/TD]
[TD="align: right"]1-11-2014[/TD]
[TD="align: right"]30-11-2014[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1-12-2014[/TD]
[TD="align: right"]31-12-2014[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
I don't understand your numbers sorry. There are 3 hours between 20:00 and 22:00 (20:00, 21:00 and 22:00). Perhaps you meant to start at 22:01.


From 20:00 to 22:00 = from 20:00 to 21:00 AND from 21:00 to 22:00. That makes 2 to me.
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
In that case why were there 30 days between 1 June and 30 June in your original post?

I understand and agree with your logical and unambiguously approach of the given problem. Unfortunately my supervisor wants it to calculate it that way. I tried to convince him that calculations for dates should be consistent with the calculations of the hours but that turned out to be a pointless effort.

So the calculations of hours should be slightly different then the dates but I think it can be down with the same formulas (with adjustments). I'm sorry for the confusion. Let me give a very straight example:
When a person works from 18:00 till 23:00 and he/she gets paid a special rate (122%) from 20:00 - 22:00 and a special rate(144%) from 22:00 - 23:00 then he gets that rate respectively for 2 hours and 1 hour. Hope this clarifies things and your help is much appreciated.
 
Upvote 0
OK try:


Excel 2010
ABCDEF
1Start_TimeEnd_TimeStartEndCountTotal_Count
200:0006:0005:0023:0015
306:0007:001
420:0022:002
522:0024:001
Sheet1
Cell Formulas
RangeFormula
E2=SUMPRODUCT(COUNTIFS(A2,"<"&(ROW(INDIRECT((C$2*24)+1&":"&(D$2*24)))/24),B2,">="&(ROW(INDIRECT((C$2*24)+1&":"&(D$2*24)))/24)))
F2=SUMPRODUCT(COUNTIFS(A2:A5,"<"&(ROW(INDIRECT((C$2*24)+1&":"&(D$2*24)))/24),B2:B5,">="&(ROW(INDIRECT((C$2*24)+1&":"&(D$2*24)))/24)))
 
Upvote 0
I'm not sure I have a full understanding of the requirement, but I'll jump back in with another try.
Is this close? If not, some more examples and expected results might help clarify.

Formula in E2, copied down.

Excel Workbook
ABCDEF
1Start_TimeEnd_TimeStartEndCountTotal_Count
20:006:005:0023:0015
36:007:001
420:0022:002
522:0024:00:001
Count Times
 
Last edited:
Upvote 0
Gentlemen, you both deserve a very big compliment. Not only for bringing in the right solution but even more for staying with me. I realize that my explanations were not always clear or unambiguously but during this process you kept looking for solutions. I really appreciate that. Men like you make this forum rock and very valuable.
This thread can go in the books as SOLVED. Thanks Peter and Andrew.
 
Upvote 0
Glad you got what you wanted. :)

Assuming my formula for column E in post #25 is producing what you want, then an adaptation of that should (I think) provide a simpler solution for that column of the earlier 'Dates' problem, even if the dates in columns A:B are not sequential, as follows.

Excel Workbook
ABCDE
1Start_Of_MonthEnd_Of_MonthStartEndCount
21/01/1431/01/1415/03/1427/07/140
31/02/1428/02/14.0
41/03/1431/03/1416
51/04/1430/04/1430
61/05/1431/05/1431
71/06/1420/06/1420
81/07/1431/07/1426
91/08/1431/08/140
101/09/1430/09/140
111/10/1431/10/140
121/11/1430/11/140
131/12/1431/12/140
Count Dates
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,987
Members
452,373
Latest member
TimReeks

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