+ Reply to Thread
Results 1 to 8 of 8

Lookup temperature based on closest time using INDEX and MATCH

  1. #1
    Registered User
    Join Date
    09-09-2014
    Location
    Portland, OR
    MS-Off Ver
    2010
    Posts
    11

    Question Lookup temperature based on closest time using INDEX and MATCH

    Hi All,

    I'm looking to find the ambient temperature based on the time in one column to the closest time of another column to bring back the temperature from that closest time.

    I tried to use VLOOKUP and the INDEX & MATCH function with no luck.

    =INDEX('09_02_Charts'!D2:D253,MATCH('09_02_Charts'!A2,Historical_Weather_Data!C2:C253,1))

    Thanks for the help!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Lookup temperature based on closest time using INDEX and MATCH

    Change the formula on the Historical_weather_data tab, Column C

    =ABS(TEXT(A2,"mm/dd/yy ") & TEXT(B2,"hh:mm:ss AM/PM"))

    And use this VLOOKUP

    =VLOOKUP(A2,Historical_Weather_Data!C:D,2,1)
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  3. #3
    Registered User
    Join Date
    09-09-2014
    Location
    Portland, OR
    MS-Off Ver
    2010
    Posts
    11

    Re: Lookup temperature based on closest time using INDEX and MATCH

    Thanks so much Speshul!

    That worked like a champ! Can't believe I've spent the better part of 4hrs trying to figure this out. So I understand the above correctly, the "ABS" simply puts the date and time with an absolute value to compare against. and then the "C:D" in the lookup table goes throughout the end of the data so when I add additional data, I no longer have to change this value. Is that correct?

  4. #4
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Lookup temperature based on closest time using INDEX and MATCH

    The ABS converts it to absolute, correct.

    In Excel 2007 and newer you can use complete row or column references. It will certainly slow down some formulas to do this (because they look through over 1 million rows or 65k columns when they calculate) but for a couple thousand vlookups you wouldn't notice the slowdown. Makes for easier and shorter formula construction, as well as not having to remember to update formulas when you add more rows.
    So in short, C:D is the equivalent of $C$1:$D$1048576

  5. #5
    Registered User
    Join Date
    09-09-2014
    Location
    Portland, OR
    MS-Off Ver
    2010
    Posts
    11

    Re: Lookup temperature based on closest time using INDEX and MATCH

    Makes complete sense.

    Thanks you very much. I've learned something new today and now with this forum in hand I can become an expert over time.

  6. #6
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Lookup temperature based on closest time using INDEX and MATCH

    I learned almost everything I know in Excel either here or in the MSDN. Stick around, you'll learn a LOT


    Welcome to the forum!

  7. #7
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Lookup temperature based on closest time using INDEX and MATCH

    I converted the dates on both worksheets to serial numbers rounded to 4 decimal places then used VLOOKUP
    Attached Files Attached Files
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  8. #8
    Registered User
    Join Date
    09-09-2014
    Location
    US
    MS-Off Ver
    2010
    Posts
    1

    Re: Lookup temperature based on closest time using INDEX and MATCH

    Quote Originally Posted by gshafiq View Post
    Hi All,

    I'm looking to find the ambient temperature based on the time in one column to the closest time of another column to bring back the temperature from that closest time.

    I tried to use VLOOKUP and the INDEX & MATCH function with no luck.

    =INDEX('09_02_Charts'!D2:D253,MATCH('09_02_Charts'!A2,Historical_Weather_Data!C2:C253,1))

    Thanks for the help!
    Quote Originally Posted by Speshul View Post
    Change the formula on the Historical_weather_data tab, Column C

    =ABS(TEXT(A2,"mm/dd/yy ") & TEXT(B2,"hh:mm:ss AM/PM"))
    This is correct

    Quote Originally Posted by Speshul View Post
    And use this VLOOKUP

    =VLOOKUP(A2,Historical_Weather_Data!C:D,2,1)
    This is almost correct. VLOOKUP returns the closest value less than or equal to the lookup value, same with MATCH having a match type of 1, but sometimes the closest value is the next time after the VLOOKUP result,e.g. row 6 on the '09_02_Charts' tab has a date/time of '8/29/2014 6:31:00 PM', for which VLOOKUP returns the temp from row 23 of the 'Historical_Weather_Data' tab (8/29/14 5:53 PM, 38 minutes before) but row 24 (8/29/14 6:53 PM, 22 minutes after) is in fact the closest time. This requires a bit more calculation to return the correct value.

    (long formula here...)
    Please Login or Register  to view this content.
    Basically compare the target date/time to the less than or equal date/time returned by index/match and then compare target to the index/match+1 (to check the next row after) and then display the results. Excel file attached, with data highlighted to show results.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Lookup closest time value based on criteria
    By ryanpog1 in forum Excel General
    Replies: 16
    Last Post: 07-10-2019, 09:15 PM
  2. Index closest match
    By MJSlattery in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-16-2013, 10:27 PM
  3. How to lookup value based on Date time closest to criteria
    By ilionel1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-08-2013, 02:01 PM
  4. [SOLVED] Index-Match Closest Value
    By CzechCzar in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-25-2013, 07:40 PM
  5. Match the Upper closest value using Index Match.
    By adnanaddo in forum Excel General
    Replies: 3
    Last Post: 01-16-2013, 02:47 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1