Lookup date/ time in range of dates and return binary value

Woofy_McWoof_Woof

Board Regular
Joined
Oct 7, 2016
Messages
60
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm attempting to return a binary 1 or 0 value where a look up of a date/time matches a date in string of dates. In the attached picture where the date and time (30 minute slots) matches the time that falls within that 30 minutes then it returns a value of 1, otherwise zero.

The date and time could contain seconds as well butstill falls within the 30 minutes and should be counted.

I've tried few things but it doesn't seem to work, any ideas? Thanks.
 

Attachments

  • lookup.JPG
    lookup.JPG
    75.5 KB · Views: 4

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try this (test with some different times and dates)

Book2
ABCDE
1StartEndDateReturn Value
201/05/2022 19:02:4901/05/2022 19:39:4901/05/2022 16:000
301/05/2022 16:300
401/05/2022 17:000
501/05/2022 17:300
601/05/2022 18:000
701/05/2022 18:300
801/05/2022 19:001
901/05/2022 19:301
1001/05/2022 20:000
1101/05/2022 20:300
1201/05/2022 21:000
1301/05/2022 21:300
1401/05/2022 22:000
Sheet1
Cell Formulas
RangeFormula
E2:E14E2=IF(AND($A$2>D2,$A$2<D3),1,IF(AND($B$2>D2,$B$2<D3),1,0))
 
Upvote 0
Try this (test with some different times and dates)

Book2
ABCDE
1StartEndDateReturn Value
201/05/2022 19:02:4901/05/2022 19:39:4901/05/2022 16:000
301/05/2022 16:300
401/05/2022 17:000
501/05/2022 17:300
601/05/2022 18:000
701/05/2022 18:300
801/05/2022 19:001
901/05/2022 19:301
1001/05/2022 20:000
1101/05/2022 20:300
1201/05/2022 21:000
1301/05/2022 21:300
1401/05/2022 22:000
Sheet1
Cell Formulas
RangeFormula
E2:E14E2=IF(AND($A$2>D2,$A$2<D3),1,IF(AND($B$2>D2,$B$2<D3),1,0))
Thank you, that worked perfectly. I should have mentioned (sorry) that I may have multiple references to search from. If I lock in the A2 and B2, how could I reference the data underneath?
 

Attachments

  • lookup1.JPG
    lookup1.JPG
    35.5 KB · Views: 4
Upvote 0
Could you clarify - would you want the return value to be a count of the number of times that fall in that slot rather than just a 1
 
Upvote 0
Could you clarify - would you want the return value to be a count of the number of times that fall in that slot rather than just a 1
I'd like to drag the formula down in Column E for the whole year and return a value of 1 where the times on the left falls within that half hour. It's pretty much the same as what is is now but increasing the range on the left rather than the just the one line at the monent.
 
Upvote 0
I've added in a couple of helper columns that lookup the start and end times and find the closest match from the table of 1/2 hour slots. Columns H & I then provide a count of Start and End tiems for each slot - does this give you something you could work with?

Book2
ABCDEFGHI
1StartEndStart LookupEnd LookupDateCount of StartCount of End
201/05/2022 01:42:2001/05/2022 02:29:2001/05/2022 01:3001/05/2022 02:0001/05/2022 00:0000
301/05/2022 03:32:1401/05/2022 04:15:1801/05/2022 03:3001/05/2022 04:0001/05/2022 00:3000
401/05/2022 05:05:1101/05/2022 05:25:1401/05/2022 05:0001/05/2022 05:0001/05/2022 01:0000
501/05/2022 07:15:1901/05/2022 07:58:4501/05/2022 07:0001/05/2022 07:3001/05/2022 01:3010
601/05/2022 08:17:1801/05/2022 09:25:4101/05/2022 08:0001/05/2022 09:0001/05/2022 02:0001
701/05/2022 02:3000
801/05/2022 03:0000
901/05/2022 03:3010
1001/05/2022 04:0001
1101/05/2022 04:3000
1201/05/2022 05:0011
1301/05/2022 05:3000
1401/05/2022 06:0000
1501/05/2022 06:3000
1601/05/2022 07:0010
1701/05/2022 07:3001
1801/05/2022 08:0010
1901/05/2022 08:3000
2001/05/2022 09:0001
2101/05/2022 09:3000
2201/05/2022 10:0000
Sheet1
Cell Formulas
RangeFormula
D2:E6D2=VLOOKUP(A2,$G$2:$G$19337,1,TRUE)
H2:H22H2=COUNTIF($D$2:$D$24,G2)
I2:I22I2=COUNTIF($E$2:$E$24,G2)
 
Upvote 0
I've added in a couple of helper columns that lookup the start and end times and find the closest match from the table of 1/2 hour slots. Columns H & I then provide a count of Start and End tiems for each slot - does this give you something you could work with?

Book2
ABCDEFGHI
1StartEndStart LookupEnd LookupDateCount of StartCount of End
201/05/2022 01:42:2001/05/2022 02:29:2001/05/2022 01:3001/05/2022 02:0001/05/2022 00:0000
301/05/2022 03:32:1401/05/2022 04:15:1801/05/2022 03:3001/05/2022 04:0001/05/2022 00:3000
401/05/2022 05:05:1101/05/2022 05:25:1401/05/2022 05:0001/05/2022 05:0001/05/2022 01:0000
501/05/2022 07:15:1901/05/2022 07:58:4501/05/2022 07:0001/05/2022 07:3001/05/2022 01:3010
601/05/2022 08:17:1801/05/2022 09:25:4101/05/2022 08:0001/05/2022 09:0001/05/2022 02:0001
701/05/2022 02:3000
801/05/2022 03:0000
901/05/2022 03:3010
1001/05/2022 04:0001
1101/05/2022 04:3000
1201/05/2022 05:0011
1301/05/2022 05:3000
1401/05/2022 06:0000
1501/05/2022 06:3000
1601/05/2022 07:0010
1701/05/2022 07:3001
1801/05/2022 08:0010
1901/05/2022 08:3000
2001/05/2022 09:0001
2101/05/2022 09:3000
2201/05/2022 10:0000
Sheet1
Cell Formulas
RangeFormula
D2:E6D2=VLOOKUP(A2,$G$2:$G$19337,1,TRUE)
H2:H22H2=COUNTIF($D$2:$D$24,G2)
I2:I22I2=COUNTIF($E$2:$E$24,G2)
Thank you, it worked though for cell E2 would this be = VLOOKUP(B2,$G$2:$G$19337,1,TRUE) ?
 
Upvote 0
Sorry, I've noticed one thing. If the Start and end time covers several hours, then it only counts the first and last half hour as 1 with the other half hours returning zero. Is there a way of ensuring that all the half hours within those hours returns 1 rather than zero?
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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