+ Reply to Thread
Results 1 to 9 of 9

Two-way lookup with INDEX and MATCH return closest match

  1. #1
    Registered User
    Join Date
    08-10-2012
    Location
    Jefferson City, MO
    MS-Off Ver
    Excel 2013
    Posts
    7

    Two-way lookup with INDEX and MATCH return closest match

    I'm working on a spreadsheet and have run into a issue using Two-way lookup with INDEX and MATCH. If the value is not in the table, I need excel to use the next highest value. However, if the exact number is in the table, I need it to use that number. Below is the formula I'm using.

    =INDEX('LarsonTable'!B4:K54,MATCH(Work!F20,'LarsonTable'!A4:A54,1),MATCH(Work!F16,'LarsonTable'!B3:K3,1))

    This formula is not showing the next highest number. It is showing the lower number. I tired using the below formula, but it's adding "1" even if it's a exact match

    =INDEX(LarsonTable!B4:K54,MATCH(Work!F20,LarsonTable!A4:A54,1)+1*ISNA(MATCH(Work!F20,LarsonTable!A4:A54,0)),MATCH(Work!F16,LarsonTable!B3:K3,1)+1*ISNA(MATCH(Work!F16,LarsonTable!B3:K3,0)))


    Below is my criteria

    Width 7/8
    UI 25

    Table where information is pulled
    UI Width
    1/2" 1"
    20 4.0 4.3
    22 4.3 4.7
    24 4.7 5.0
    26 5.0 5.3
    28 5.3 5.7

    In this example, I need to use the UI of 26 and the Width of 1", to get a Width of Molding of 5.3. My current formula is pulling the UI of 24 and the Width of 1/2" making me have a Width of Molding of 4.7.
    If I have a UI of 28 and a width of 1/2", I need to use the exact value which will equal Width of Molding of 5.3

    Thanks,

  2. #2
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Two-way lookup with INDEX and MATCH return closest match

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Two-way lookup with INDEX and MATCH return closest match

    Try this
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    where the values 1/2'' and 1'' are written with a single quote twice (code 039 not double quote code 112)
    See the file to clarification
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,814

    Re: Two-way lookup with INDEX and MATCH return closest match

    The formula you originally should be able to work with two small adjustments (assuming you are allowed to make these adjustments):

    1) Use -1 as the third argument to the MATCH() functions instead of 1 and =INDEX('LarsonTable'!B4:K54,MATCH(Work!F20,'LarsonTable'!A4:A54,-1),MATCH(Work!F16,'LarsonTable'!B3:K3,-1))
    2) Sort your table so the lookup row/column are in descending order.
    empty -- 1 -- 1/2
    28 -- 5.7 -- 5.3
    26 -- 5.3 -- 5.0
    and so on
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Registered User
    Join Date
    08-10-2012
    Location
    Jefferson City, MO
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Two-way lookup with INDEX and MATCH return closest match

    Thanks for you input. I'm still having issues with the formula. I have attached the actual file for your convenience. For product number 246350 and a Frame size of 11 X 14, the Inches is 25. Since there is no 25 on the LJT, I need to use the next highest number which is 26. The frame width for this product number is 7/8" and I need to use 1". So the Width of Molding in Inches should be 5.3, not 4.7. Which will make the total wholesale price $14.70 not $13.82 as indicated.

    Also, if I use Product number 431485 with a Frame size of 30 X 40, the United Inches will be 70. Since the chart has both 1 1/2" and 70, the Width of Molding would be 13.3. But in the same example if I change the Frame size to 11 X 14 , which will make the united inches 25, I will need to use 26 united inches with the 1 1/2'' Width of Molding.

    I hope this make sense.
    Attached Files Attached Files

  6. #6
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Two-way lookup with INDEX and MATCH return closest match

    Hi
    You can use this formula in F21
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    but @MrShorty proposed a better solution if you can use the sorted table LJT!A3:K54 in descending order as I do in LJTNew in both directions
    Formula using LJTNew .

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    See the file
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,814

    Re: Two-way lookup with INDEX and MATCH return closest match

    I don't know if you are trying Jose's or my proposed solution. As my solution applies to your sample file, I note that the lookup ranges in LJT are still sorted in ascending order, and the MATCH() functions are still using +1 for the 3rd argument. In order to implement my solution I:

    0) Made copies of LJT and Work so I would not lose your originals.
    1) I need to sort the table in LJT so the lookup ranges are both sorted in descending order:
    1a) Select A3:K54 -> Data -> Sort -> by column 1/A, largest to smallest, make sure "my data has headers" is checked, (am I missing anything?) -> Sort
    1b) Select B3:K54 -> Data -> Sort -> Options -> Sort left to right -> sort by row 3 largest to smallest (am I missing anything?) -> Sort
    2) Go to Work and notice the N/A error in F21 (caused by the sort operation in step 1). Select F21 -> F2 (edit) -> put a negative sign - in front of each of the "match type" arguments in the two MATCH() functions =INDEX(...,MATCH(...,-1),MATCH(...,-1)). Result is 5.3 (as expected).
    3) To check, pull up the "evaluate formula" tool (https://support.office.com/en-us/art...6-a70aa409b8a7 ) and step through the function. The "row" MATCH() function is returning 44 (table starts in row 3, so this is row 47 of LJT) and the "column" MATCH() function is returning 9 (table starts in column A, so this is column J of LJT). Look in LJT and see if J47 is indeed the expected return cell. J47 corresponds to 26 (lookup value was 25, so this looks right) and 1 (lookup value was 7/8, so this also looks right).
    4) Enter different values in F16 and F20 of Work to see if the lookup value returns the correct values (as near as I could tell, it looked just fine).

    As indicated in my first post, the big question is if you are allowed to sort the table in LJT in descending order or if that will cause a big uproar with the other users who need to use this spreadsheet. If sorting the table in LJT is allowed, that should work.

  8. #8
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Two-way lookup with INDEX and MATCH return closest match

    Hi @MrShorty

    I implemented both solutions using a new LJT sheet called LJTnew in the file I attached in Post # 6, to avoid any problems.
    LJTNew has the ordered table as you proposed and the spreadsheet has my formula and your formula is in a parallel cell, because I think your solution is better than mine.
    I do not know if it can be used by keeping both sheets using one for one propose and another for other propose.

  9. #9
    Registered User
    Join Date
    08-10-2012
    Location
    Jefferson City, MO
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Two-way lookup with INDEX and MATCH return closest match

    Thanks for all the help........

+ 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. [SOLVED] Index/match return value row1 and value column A closest > search value
    By 323428 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 03-25-2018, 03:15 PM
  2. Replies: 2
    Last Post: 12-18-2014, 09:52 AM
  3. Index&Match formula for closest match(s)
    By hom100 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-16-2014, 02:40 PM
  4. [SOLVED] Lookup temperature based on closest time using INDEX and MATCH
    By gshafiq in forum Excel General
    Replies: 7
    Last Post: 09-09-2014, 03:58 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
  6. LOOKUP to return closest match
    By Kateabc in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-18-2008, 12:56 PM
  7. lookup & return closest match
    By Joanie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2006, 10:46 PM

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