Formula to count entries that fall on a specific day and time range

meronymous

New Member
Joined
Feb 21, 2016
Messages
9
Hello everyone,

I'm hoping someone can help me come up with a formula to count the number of entries that fall on a specific day of the week and within a specific time range. I have a long table of data in Excel that includes two columns: "Entry Time" and "Exit Time". These columns are formatted as "dd.mm.yyyy HH:mm", and the time between the two can span over several days.

What I need is a formula that checks if the period between Entry Time and Exit Time both fall on a specific day of the week (e.g., Wednesday) and within a specific time range (e.g., between 8:00 AM and 10:00 AM). If the conditions are met, I want to add 1 to the count.
I have no problem doing this when B and C are on the same date, but I struggle to find a way to make Excel count as + 1 all the hours and days in between when the difference between B and C goes over midnight.

Here's a screenshot of my table:

1680591477988.png


If anyone could help me put this together, I'd be very grateful!

Thanks in advance.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
is this what you're after?

Book1
ABCDEF
1Between
2EnterExitWeekday10:0012:00
304/04/2023 10:1004/04/2023 11:101FALSE 
404/04/2023 10:1004/04/2023 11:102FALSE 
504/04/2023 10:1004/04/2023 11:103TRUE1
604/04/2023 09:1004/04/2023 10:103FALSE 
704/04/2023 10:1004/04/2023 15:103FALSE 
804/04/2023 10:1004/04/2023 11:106FALSE 
904/04/2023 10:1004/04/2023 11:107FALSE 
Sheet1
Cell Formulas
RangeFormula
E3:E9E3=AND(WEEKDAY(A3)=D3,WEEKDAY(B3)=D3,AND(A3-INT(A3)>=E$2,B3-INT(B3)<=F$2))
F3:F9F3=IF(E3,1,"")
 
Upvote 0
Close, but not exactly that.
I want the table on the right to go only from 1 to 7 (the seven days in a week).
In E5 the correct result would be 6, meaning in column A:B there's 6 occurrences being both on day 3 and between 10:00 and 11:00.

I've managed to do this already with some slightly different formulas, but I can't make it work when the value in A:B (in your example) are something like 02/04/2023 10:00 and 05/04/2023 12:00.
This pair of values should as well be considered as +1 in cell E5, putting the end result to 7.
 
Upvote 0
ok, try this

Book1
ABCDEF
1Between
2EnterExitWeekday10:0012:00
304/04/2023 10:1004/04/2023 11:1010
404/04/2023 10:1004/04/2023 11:1020
504/04/2023 10:1004/04/2023 11:1035
604/04/2023 09:1004/04/2023 10:1040
704/04/2023 10:1004/04/2023 15:1052
804/04/2023 10:1004/04/2023 11:1060
904/04/2023 10:1004/04/2023 11:1070
1006/04/2023 10:1006/04/2023 11:10
1106/04/2023 10:1006/04/2023 11:10
1206/04/2023 09:1006/04/2023 10:10
1306/04/2023 10:1006/04/2023 15:10
14
Sheet1
Cell Formulas
RangeFormula
E3:E9E3=SUMPRODUCT((($A$3:$A$13)-INT($B$3:$B$13)>=E$2)*(($B$3:$B$13)-INT($B$3:$B$13)<=F$2)*(WEEKDAY($A$3:$A$13)=D3)*(WEEKDAY($B$3:$B$13)=D3))
 
Upvote 0
Close, but not exactly that.
I want the table on the right to go only from 1 to 7 (the seven days in a week).
In E5 the correct result would be 6, meaning in column A:B there's 6 occurrences being both on day 3 and between 10:00 and 11:00.

I've managed to do this already with some slightly different formulas, but I can't make it work when the value in A:B (in your example) are something like 02/04/2023 10:00 and 05/04/2023 12:00.
This pair of values should as well be considered as +1 in cell E5, putting the end result to 7.

sorry, just read that
02/04/2023 10:00 and 05/04/2023 12:00. This pair of values should as well be considered as +1 in cell E5, putting the end result to 7.
but they are not on the same day?
 
Upvote 0
sorry, just read that

but they are not on the same day?
Well,
02/04/2023 10:00 and 05/04/2023 12:00 should get a +1 generated for every hour cell on day 1 (from 10), on every single hour on day 2, 3, and finally start again giving 0 after 12 on day 4 (05/04/23 12:00).
This while taking in account all the other values in columns A:B.
 
Upvote 0
have a look if this works for you, col E is entry between the set time and col F is exit. G is the maximun of the 2.

Book1
ABCDEFG
1Between
2EnterExitWeekday09:0012:30
304/04/2023 10:1004/04/2023 11:101000
404/04/2023 10:1004/04/2023 11:102000
504/04/2023 10:1004/04/2023 11:103757
604/04/2023 09:1004/04/2023 10:104101
704/04/2023 10:1004/04/2023 15:105355
804/04/2023 10:1004/04/2023 11:106000
904/04/2023 10:1006/04/2023 11:107000
1006/04/2023 10:1006/04/2023 11:10
1106/04/2023 10:1006/04/2023 11:10
1206/04/2023 09:1006/04/2023 10:10
1305/04/2023 10:1006/04/2023 11:10
Sheet2
Cell Formulas
RangeFormula
E3:E9E3=SUMPRODUCT((($A$3:$A$13)-INT($A$3:$A$13)>=E$2)*(WEEKDAY($A$3:$A$13)=D3))
F3:F9F3=SUMPRODUCT((($B$3:$B$13)-INT($B$3:$B$13)<=F$2)*(WEEKDAY($B$3:$B$13)=D3))
G3:G9G3=MAX(E3:F3)
 
Upvote 0
have a look if this works for you, col E is entry between the set time and col F is exit. G is the maximun of the 2.

Book1
ABCDEFG
1Between
2EnterExitWeekday09:0012:30
304/04/2023 10:1004/04/2023 11:101000
404/04/2023 10:1004/04/2023 11:102000
504/04/2023 10:1004/04/2023 11:103757
604/04/2023 09:1004/04/2023 10:104101
704/04/2023 10:1004/04/2023 15:105355
804/04/2023 10:1004/04/2023 11:106000
904/04/2023 10:1006/04/2023 11:107000
1006/04/2023 10:1006/04/2023 11:10
1106/04/2023 10:1006/04/2023 11:10
1206/04/2023 09:1006/04/2023 10:10
1305/04/2023 10:1006/04/2023 11:10
Sheet2
Cell Formulas
RangeFormula
E3:E9E3=SUMPRODUCT((($A$3:$A$13)-INT($A$3:$A$13)>=E$2)*(WEEKDAY($A$3:$A$13)=D3))
F3:F9F3=SUMPRODUCT((($B$3:$B$13)-INT($B$3:$B$13)<=F$2)*(WEEKDAY($B$3:$B$13)=D3))
G3:G9G3=MAX(E3:F3)
Thanks for your help,
it's absolutely going in the right direction, even though I think we still don't totally understand each other.
The table on the right doesn't need to show entry and exit.
Only presence at a given time, that I get from the columns you put in A:B.

Even though we are not talking hospitality imagine it that way:
guest checks in at timestamp A2 and checks out at C2. The time spent in between can be a few hours or several days.
I need with only this information a whole table that visualizes the occupancy rate per day and time of the day from the timestamps in A2:B2.

The idea is to use this analysis to understand when and where to make some services available, depending on what times and days there's more need as summed up in tabel E:G.
Ideally the level of detail should be 15 minutes, but if I get way to work around the midnight / dayshift issue I should be able to make it more detailed myself.
 
Upvote 0
Cols E & F just to show you the make up of the formula that can be combined into one like this, the question is dose it give you the desired answer,

Book1
ABCDEF
1Between
2EnterExitWeekday09:0012:30
304/04/2023 10:1004/04/2023 11:1010
404/04/2023 10:1004/04/2023 11:1020
504/04/2023 10:1004/04/2023 11:1037
604/04/2023 09:1004/04/2023 10:1041
704/04/2023 10:1004/04/2023 15:1055
804/04/2023 10:1004/04/2023 11:1060
904/04/2023 10:1006/04/2023 11:1070
1006/04/2023 10:1006/04/2023 11:10
1106/04/2023 10:1006/04/2023 11:10
1206/04/2023 09:1006/04/2023 10:10
1305/04/2023 10:1006/04/2023 11:10
Sheet2
Cell Formulas
RangeFormula
E3:E9E3=MAX(SUMPRODUCT((($A$3:$A$13)-INT($A$3:$A$13)>=E$2)*(WEEKDAY($A$3:$A$13)=D3)),SUMPRODUCT((($B$3:$B$13)-INT($B$3:$B$13)<=F$2)*(WEEKDAY($B$3:$B$13)=D3)))
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,128
Members
453,021
Latest member
Justyna P

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