VLOOKUP with time range conditions?

RyanHillAZ

New Member
Joined
Oct 31, 2014
Messages
10
Hello Everyone,

I am trying to figure out how to write a formula to verify if a bus made it to the scheduled stop within a given window of time.

My data shows the bus schedule and it also shows any bus that arrived within the given landmark (geo-fence) within a period of time.

I would like to be able to say "If any vehicle arrived within the landmark stop (ex. 411 Stop C @ 9:15 AM) at least 30 minutes prior to 9:15 AM and within 5 minutes after 9:15 AM."

I am not even close to figuring this one out. The nearest reference that I could find on the message board was the post of "VLOOKUP with Time Range" - http://www.mrexcel.com/forum/excel-questions/384955-vlookup-time-range.html

But I am not proficient with INDEX or MATCH functions.

Here is some of my sample data: This comes from a report showing when the bus actually arrived within the given landmark location.
VEHICLE
Landmark

<tbody>
</tbody>
First In

<tbody>
</tbody>
Last In

<tbody>
</tbody>
701
411 stop C
5:42 AM

<tbody>
</tbody>
5:47 AM

<tbody>
</tbody>
701411 stop C
6:20 AM

<tbody>
</tbody>
6:20 AM

<tbody>
</tbody>
701411 stop C
7:13 AM

<tbody>
</tbody>
7:16 AM

<tbody>
</tbody>
701411 stop C
7:50 AM

<tbody>
</tbody>
7:50 AM

<tbody>
</tbody>

<tbody>
</tbody>
701411 stop C
8:42 AM

<tbody>
</tbody>
8:46 AM

<tbody>
</tbody>
701411 stop C
9:20 AM

<tbody>
</tbody>
9:21 AM

<tbody>
</tbody>
701411 stop C
10:13 AM

<tbody>
</tbody>
10:17 AM

<tbody>
</tbody>
701411 stop C
10:50 AM

<tbody>
</tbody>
10:50 AM

<tbody>
</tbody>
701411 stop C
11:45 AM

<tbody>
</tbody>
11:47 AM

<tbody>
</tbody>

<tbody>
</tbody>


Here is the route information as to when the bus is supposed to be at the stop location.

DirectionLandmarkScheduled TimeActual Time(+,-)Decimal(Y,N)%
Northbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
9:16 AM

<tbody>
</tbody>
? formula ?=D2-C2=E2On Time?=IF((F2="Y"),1,IF((F2="N"),0))
Northbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
10:16 AM

<tbody>
</tbody>
? formula ?=D3-C3
Northbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
1:16 PM

<tbody>
</tbody>
? formula ?
Northbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
2:16 PM

<tbody>
</tbody>
? formula ?
Northbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
5:16 PM

<tbody>
</tbody>
? formula ?
Southbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
9:15 AM

<tbody>
</tbody>

<tbody>
</tbody>
? formula ?
Southbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
10:15 AM

<tbody>
</tbody>
? formula ?
Southbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
1:15 PM

<tbody>
</tbody>
? formula ?
Southbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
2:15 PM

<tbody>
</tbody>
? formula ?
Southbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
5:15 PM

<tbody>
</tbody>
? formula ?

<tbody>
</tbody>


Columns E, F, G, & H can be ignored in the above example. They are basically helper columns to convert the time into a decimal and identify if the bus made the stop within a given time.

The full data excel can be found on my google drive link if you would like to see the full landmark history sheet and the validation worksheet that I am working to create.

Excel Link: https://drive.google.com/file/d/0B-z07hmwXXmIeFJCaHp0V0tDVms/view?usp=sharing

Thanks so much!

Ryan Hill
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hello Everyone,

I am trying to figure out how to write a formula to verify if a bus made it to the scheduled stop within a given window of time.

My data shows the bus schedule and it also shows any bus that arrived within the given landmark (geo-fence) within a period of time.

I would like to be able to say "If any vehicle arrived within the landmark stop (ex. 411 Stop C @ 9:15 AM) at least 30 minutes prior to 9:15 AM and within 5 minutes after 9:15 AM."

I am not even close to figuring this one out. The nearest reference that I could find on the message board was the post of "VLOOKUP with Time Range" - http://www.mrexcel.com/forum/excel-questions/384955-vlookup-time-range.html

But I am not proficient with INDEX or MATCH functions.

Here is some of my sample data: This comes from a report showing when the bus actually arrived within the given landmark location.
VEHICLE
Landmark

<tbody>
</tbody>
First In

<tbody>
</tbody>
Last In

<tbody>
</tbody>
701411 stop C
5:42 AM

<tbody>
</tbody>
5:47 AM

<tbody>
</tbody>
701411 stop C
6:20 AM

<tbody>
</tbody>
6:20 AM

<tbody>
</tbody>
701411 stop C
7:13 AM

<tbody>
</tbody>
7:16 AM

<tbody>
</tbody>
701411 stop C
7:50 AM

<tbody>
</tbody>
7:50 AM

<tbody>
</tbody>

<tbody>
</tbody>
701411 stop C
8:42 AM

<tbody>
</tbody>
8:46 AM

<tbody>
</tbody>
701411 stop C
9:20 AM

<tbody>
</tbody>
9:21 AM

<tbody>
</tbody>
701411 stop C
10:13 AM

<tbody>
</tbody>
10:17 AM

<tbody>
</tbody>
701411 stop C
10:50 AM

<tbody>
</tbody>
10:50 AM

<tbody>
</tbody>
701411 stop C
11:45 AM

<tbody>
</tbody>
11:47 AM

<tbody>
</tbody>

<tbody>
</tbody>


Here is the route information as to when the bus is supposed to be at the stop location.

DirectionLandmarkScheduled TimeActual Time(+,-)Decimal(Y,N)%
Northbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
9:16 AM

<tbody>
</tbody>
? formula ?=D2-C2=E2On Time?=IF((F2="Y"),1,IF((F2="N"),0))
Northbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
10:16 AM

<tbody>
</tbody>
? formula ?=D3-C3
Northbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
1:16 PM

<tbody>
</tbody>
? formula ?
Northbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
2:16 PM

<tbody>
</tbody>
? formula ?
Northbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
5:16 PM

<tbody>
</tbody>
? formula ?
Southbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
9:15 AM

<tbody>
</tbody>

<tbody>
</tbody>
? formula ?
Southbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
10:15 AM

<tbody>
</tbody>
? formula ?
Southbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
1:15 PM

<tbody>
</tbody>
? formula ?
Southbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
2:15 PM

<tbody>
</tbody>
? formula ?
Southbound

<tbody>
</tbody>
411 stop C

<tbody>
</tbody>
5:15 PM

<tbody>
</tbody>
? formula ?

<tbody>
</tbody>


Columns E, F, G, & H can be ignored in the above example. They are basically helper columns to convert the time into a decimal and identify if the bus made the stop within a given time.

The full data excel can be found on my google drive link if you would like to see the full landmark history sheet and the validation worksheet that I am working to create.

Excel Link: https://drive.google.com/file/d/0B-z07hmwXXmIeFJCaHp0V0tDVms/view?usp=sharing

Thanks so much!

Ryan Hill

Hi Ryan,

Haven't been able to finish this, so i would though i would show what I had done and see it someone can come up with a formal which works.

First you need to custom format the cell with this: (got this at https://support.office.com/en-ca/ar...-of-time-9a6558a1-a86b-41d4-b244-1000fc7d31e9)

On the Home tab, in the Cells group, click Format, and then click Format Cells.

In the Format Cells dialog box, click the Number tab.

Under Category, click Custom.

In the Type box, type [h]:mm.

TIP You can also show the results in minutes and seconds by setting the format to [m]:ss, or minutes only by typing [m].

Click OK.

Excel displays 28:15 if you used the format [h]:mm).

Then a simple =D2-C2 to get the time from the actual arrival to Scheduled Time (Format this column with the custom format as well)

Now have tried all sorts of AND and IF functions but can't get it to work.

It doesn't seem to like the 0:30 in anything I know. Let see it someone can figure it out!
 
Upvote 0
Actually you need to use an ABS function in case the bus comes really early.

=ABS(C14-D14) will do it.

Next try this formula =IF(COUNT(E14),IF(E14>TIME(0,30,0),"Not On Time","On Time"),"")

Its working for me, but I have tried so many equations I have gone cabin crazy!

If it doesn't will go back to the drawing board!
 
Upvote 0
Hi Cosmic Wizard,

Thank you so much for all of your work on this! I am not sure where to place the formulas you mentioned.

1. =ABS(C14-D14) where does this one go? What does it accomplish?

2.
=IF(COUNT(E14),IF(E14>TIME(0,30,0),"Not On Time","On Time"),"") where does this one go?

Thanks,

Ryan
 
Upvote 0
Hi Cosmic Wizard,

Thank you so much for all of your work on this! I am not sure where to place the formulas you mentioned.

1. =ABS(C14-D14) where does this one go? What does it accomplish?

2.
=IF(COUNT(E14),IF(E14>TIME(0,30,0),"Not On Time","On Time"),"") where does this one go?

Thanks,

Ryan

Here we go:

Scheduled Time Actual Time Difference Result

9:16 AM 9:26 AM 0:10 On Time
 
Upvote 0
Here we go:

Scheduled Time Actual Time Difference Result

9:16 AM 9:26 AM 0:10 On Time


Gotcha, that makes sense.

The part that I am still having trouble with is finding a formula which can review the data in the other table to determine time at which the bus entered the landmark zone from the other spreadsheet.

I am hoping there is a formula which can review the name of the landmark. [411 Stop C] then check the scheduled arrival time [9:19am] and review the data in the other spreadsheet to return a value of the nearest time to the scheduled time.
 
Upvote 0
Gotcha, that makes sense.

The part that I am still having trouble with is finding a formula which can review the data in the other table to determine time at which the bus entered the landmark zone from the other spreadsheet.

I am hoping there is a formula which can review the name of the landmark. [411 Stop C] then check the scheduled arrival time [9:19am] and review the data in the other spreadsheet to return a value of the nearest time to the scheduled time.

Just a couple of quick questions;

Do you mean to say you just want a count of the number of times a bus was on time at Stop C??

If so a simple COUNTIF function will do:

On Time =COUNTIF(F2:F20,D24) where cell D24 has the text On Time in it; and F2:F20 is the column where the result are in

Not On Time =COUNTIF(F4:F22,D26) same as above.

Or you could use Data Validation so you can swap between Stops to find the data.

=COUNTIFS(F2:F20,D24,B2:B20,D28) is the formula to use, where D28 is the cell where your validation list is, and B2:B20 is the range of bus stops for your validation list.

Your could also your data validation for your "On Time" and "Not On Time" choices, to simplified the process.
 
Upvote 0
Just a couple of quick questions;

Do you mean to say you just want a count of the number of times a bus was on time at Stop C??

If so a simple COUNTIF function will do:

On Time =COUNTIF(F2:F20,D24) where cell D24 has the text On Time in it; and F2:F20 is the column where the result are in

Not On Time =COUNTIF(F4:F22,D26) same as above.

Or you could use Data Validation so you can swap between Stops to find the data.

=COUNTIFS(F2:F20,D24,B2:B20,D28) is the formula to use, where D28 is the cell where your validation list is, and B2:B20 is the range of bus stops for your validation list.

Your could also your data validation for your "On Time" and "Not On Time" choices, to simplified the process.


No, I am not looking for the count of On Time arrivals.

I will try to better explain the first issue.

I have the bus schedule in one spreadsheet. I have the number of times any number of different buses entered the landmark location in which the bus stop is located in the next spreadsheet.

I am trying to write a formula which will look at the bus schedule spreadsheet and review 2 variables. 1) The name of the bus stop 2) The scheduled time of arrival. I then want to take that information (Stop = 411 Stop 1, Scheduled Time = 9:19 AM) and review the landmark history information to find the following.

Return a time in which any bus entered the 411 Stop 1 within a time frame of 30 minutes before 9:19 AM and within 5 minutes after 9:19 AM. So the formula would be checking the range of cells within the landmark history spreadsheet to try and find the nearest time to that (if there is one) and return the time to my bus stop spreadsheet.

DirectionLandmarkScheduled TimeActual Time(+,-)Decimal (Y,N)%
Northbound411 Stop 19:190:01:000.0007Y1
Northbound411 Stop 110:1910:19:000.4299N0
Northbound411 Stop 113:1913:19:000.5549N0
Northbound411 Stop 114:1914:19:000.5965N0
Northbound411 Stop 117:1917:19:000.7215N0
Northbound411 Stop 118:1918:19:000.7632N0
Southbound411 Stop 19:139:13:000.3840N0
Southbound411 Stop 110:1310:13:000.4257N0
Southbound411 Stop 113:1313:13:000.5507N0
Southbound411 Stop 114:1314:13:000.5924N0
Southbound411 Stop 117:1317:13:000.7174N0
Southbound411 Stop 118:1318:13:000.7590N0
Southbound411 Stop 106:216:21:000.2646N0
Southbound411 Stop 107:067:06:000.2958N0

<colgroup><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>


VehicleVINSerial NumberDriverLandmarkFirst InFirst InLast InStill InDistance (miles)Time Inside (hours)Idling Inside (hours)Stopped Inside (hours)First OdometerLast OdometerHeading
7651FDFE4FS9DDB194764641293469not set411 stop 15/26/15 12:00 AM10:1210:12 AM0000075,512.5075,512.50N
7651FDFE4FS9DDB194764641293469not set411 stop 15/26/15 12:00 AM13:151:15 PM0000075,555.6075,555.60N
7651FDFE4FS9DDB194764641293469not set411 stop 15/26/15 12:00 AM14:182:18 PM0000075,575.9075,575.90N
7651FDFE4FS9DDB194764641293469not set411 stop 15/26/15 12:00 AM17:105:10 PM0000075,618.6075,618.60N
7671FDFE4FS6DDB274544641294457not set411 stop 15/26/15 12:00 AM7:067:06 AM0000097,109.6097,109.60N
7671FDFE4FS6DDB274544641294457not set411 stop 15/26/15 12:00 AM11:1211:12 AM0000097,222.2097,222.20N
7671FDFE4FS6DDB274544641294457not set411 stop 15/26/15 12:00 AM12:1612:16 PM0000097,257.0097,257.00N
7671FDFE4FS6DDB274544641294457not set411 stop 15/26/15 12:00 AM18:336:33 PM0000097,428.0097,428.00N

<colgroup><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Return a time in which any bus entered the 411 Stop 1 within a time frame of 30 minutes before 9:19 AM and within 5 minutes after 9:19 AM. So the formula would be checking the range of cells within the landmark history spreadsheet to try and find the nearest time to that (if there is one) and return the time to my bus stop spreadsheet.

Stop if I am on the wrong tract, but you want the nearest time to 9:19 over say the course of a day, 30 mins before and 5 mins after.

So basically one time which is the closest to 9:19, like 9:21???
 
Upvote 0
Stop if I am on the wrong tract, but you want the nearest time to 9:19 over say the course of a day, 30 mins before and 5 mins after.

So basically one time which is the closest to 9:19, like 9:21???

Yes, that is exactly what I am looking for. Thanks so very much!
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

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