+ Reply to Thread
Results 1 to 10 of 10

Vlookup with closest match and exact match

  1. #1
    Registered User
    Join Date
    07-28-2010
    Location
    nyc
    MS-Off Ver
    Excel 2010
    Posts
    6

    Vlookup with closest match and exact match

    Here a sample of the data I'm working with, in columns A-C (data is much more extensive obviously:
    1000 61.2 306.5
    1000 70.5 330.2
    2000 72.3 312.7
    2000 92.8 370.6
    3000 62.5 314.9
    3000 92.6 340.5

    I want the user to be able to input two values which will be checked against columns A and B, and return the corresponding value in C. The lookup for the column A value should be exact, but the column B lookup should be the closest match. However, the closest match should be filtered by the lookup of column A first.

    For example, lets say the user inputs 3000 and 94. The formula should filter all data by the 3000 input first, then find the closest match in column B for just that dataset, and return the corresponding value in column C (in the example, it should return 340.5).

    I tried a combination of index-match, vlookup, and filtered arrays, but couldn't figure it out. The biggest problem I was having was figuring out how to have the formula filter first by column A, then find the closest match in column B for the filtered data.

    Also, in the example I noted, if 3000 is changed to 2000, then the formula should return 370.6.

    Thanks in advance for your help!

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Vlookup with closest match and exact match

    Try this array formula entered with CTRL + SHIFT + ENTER

    =LOOKUP(3000+94,A1:A6+B1:B6,C1:C6)

    The 3 ranges must be finite, no blanks beyond the end of the table.
    The table must be sorted Ascending by column A then Ascending by column B.

  3. #3
    Registered User
    Join Date
    07-28-2010
    Location
    nyc
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Vlookup with closest match and exact match

    Sorted the columns as you said and tried the formula. It seems to work for the most part, but for example, two data points like this gave it trouble:

    2000 61.51 288.82
    2000 70.49 297.07

    Inputting 2000 and 70 returns 288.82 instead of 297.07

  4. #4
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Vlookup with closest match and exact match

    Of course it does, why wouldn't it?
    Lookup finds the largest value that is less than or equal to the lookup value.
    70 is less than 70.49
    70 is greater than 61.51
    So it returns 288.82 (The value corresponding to 61.51, the largest value less than or equal to 70)

  5. #5
    Registered User
    Join Date
    07-28-2010
    Location
    nyc
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Vlookup with closest match and exact match

    Right, I guess I should have been more clear. As I had originally posted, I want to find the closest match (in absolute value terms) in column B.

    So in the example I mentioned, 70 is much closer to 70.49 than 61.51.

    Any alternatives?

  6. #6
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Vlookup with closest match and exact match

    Ah, OK.
    Sounded like you were only talking about the difference between "exact match" and "closest match" as they are related to the Vlookup Function.

    What you're describing now is an entirely different and much more complicated issue.

    Hang on....

  7. #7
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Vlookup with closest match and exact match

    Try this (again entered with CTRL + SHIFT + ENTER)

    =INDEX(C1:C6,MATCH(MIN(ABS((G1+H1)-(A1:A6+B1:B6))),ABS((G1+H1)-(A1:A6+B1:B6)),0))

    G1 and H1 are the 2 lookup values like 2000 and 70

  8. #8
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Vlookup with closest match and exact match

    Hi,

    Try this array formula:

    =INDEX($C$1:$C$6,MATCH(TRUE,ABS($F$1-$B$1:$B$6)=MIN(IF($A$1:$A$6=$E$1,ABS($F$1-$B$1:$B$6))),0))

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  9. #9
    Registered User
    Join Date
    07-28-2010
    Location
    nyc
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Vlookup with closest match and exact match

    Thank you Jonmo1 and XOR LX! Both solutions seem to be working. I had a similar formula, just couldn't seem to make it work!

  10. #10
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Vlookup with closest match and exact match

    You're welcome, thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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