+ Reply to Thread
Results 1 to 12 of 12

INDEX and MATCH not returning proper values

  1. #1
    Registered User
    Join Date
    12-20-2023
    Location
    Massachusetts
    MS-Off Ver
    Excel for Mac 365 vs. 16.67
    Posts
    5

    INDEX and MATCH not returning proper values

    I have a bit of a conundrum. I am trying to match a concatenation of cells with that in another column. This concatenation essentially equals "198-1209B-26H", for example. When looking in column N, I want to find the cells that match that concatenation. In this example, starting at row 66, that means the matched values should then match to the following range N545:N562. I then want to extract the value that is in the very most top of that range that I place in column L. In another cell, column M, I want to also extract the value that is in the very last row of that matched range. As you can see, in column M, it works fine. But in column L, the very top value is matching with cells otuside of the match range. This makes zero sense. The same formula works for the whoel dataset except for anything that starts with 198-1209B; it works fine for anything with the start of 198-1209A, 198-1209C, 198-1210A, 198-1210B. I've been going in circles. If I delete the first few rows in N that start with 198-1209B-1H then it returns fine.

    Attached is the sheet I'm working on. I've highlighting in orange where the formula breaks down.


    excel help.xlsx

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: INDEX and MATCH not returning proper values

    Removed by JT
    Last edited by JohnTopley; 12-20-2023 at 03:08 PM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

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

    Re: INDEX and MATCH not returning proper values

    As explained in the help file, when you have the 3rd argument of the MATCH() function set to 1, the search data MUST be sorted in ascending order. Since the data are text, that means text sort order. In text sort order, 21H, 26H, 28H (etc) all come before 2H. In column N, however, 2H is before 26H, so MATCH()'s binary search algorithm fails because the data in column N are not correctly sorted.

    It's a large data set (1400 rows), so I didn't take the time to try to figure out a detailed solution to propose. It might be enough to just sort the lookup table on column N. If not, you will need to think through your search algorithm more carefully.

    If you decide you need more help, I recommend scaling the data set back to something more manageable but still representative of the problem. Then we can look at your data storage and searching requirements and help with solutions that can then be scaled back up to your larger data set.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    12-20-2023
    Location
    Massachusetts
    MS-Off Ver
    Excel for Mac 365 vs. 16.67
    Posts
    5

    Re: INDEX and MATCH not returning proper values

    L66 does not find the proper value, though. If it did, it should return 198-1209B-26H, but it does not. Instead it returns 198-1209B-1H. I know that M returns the proper last value, because if I change the formula slightly where the formula ends in ,2) to grab from column O it would return the correct value at the end of the matched values. I need this formula in column L to work properly because based on that, I'm going to set up a more complicated formula that is not worth going into, but it requires that condition to be true, and so far it is not.

    INDEX($N$4:$P$1423,MATCH(B66&"-"&C66&D66&"-"&E66&F66,$N$4:$N$1423, 1),2) would return the value from column O that I will eventually want to extract, I just have it set the way it is now to confirm it's matching the right row without having to go back and forth.

  5. #5
    Registered User
    Join Date
    12-20-2023
    Location
    Massachusetts
    MS-Off Ver
    Excel for Mac 365 vs. 16.67
    Posts
    5

    Re: INDEX and MATCH not returning proper values

    But the same situation occurs for rows that contain something like 1209A-26H where it will also return 1209A-26H and not 1209A-1H. So I get what you're saying about the sort order, but I'm confused why it will work for 1209A but not 1209B. Also, if I were to just delete any reference to 1209A in columns N down to the start of 1209B and apply the same formula, it will then correctly find 1209B-26H and not link to 1209B-1H.

    I've had tunnel vision on this for about a week so maybe I'm misunderstanding you, but again, to me 1209A has the same set up as 1209B and yet it works for that.

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: INDEX and MATCH not returning proper values

    for the LAST row try:

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

  7. #7
    Registered User
    Join Date
    12-20-2023
    Location
    Massachusetts
    MS-Off Ver
    Excel for Mac 365 vs. 16.67
    Posts
    5

    Re: INDEX and MATCH not returning proper values

    So perhaps I am going about this all wrong. Basically I have ID info in columns B:G. I need to find rows in column N that are an EXACT match. Once those rows are isolated, I then need to do a search within those matched rows for certain things, such as values that are one above or one cell below what is in cell "I". In other cases, I need to get the very last possible value in the matched array. I tried my best to make this equation, but it for some reason is not matching the IDs how I need them to match since, as I've already said, 198-1209B-26H is NOT the same as 198-1209B-1H, but based on what I already wrote in the formula, it keeps finding that to be match. Sorry if I'm going in circles here. That's where my brain is at, haha.

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: INDEX and MATCH not returning proper values

    Did you try post #6 ?

  9. #9
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: INDEX and MATCH not returning proper values

    My suggestion for better reading your formula in column K:

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


    Separating the if condition and placing new variables.
    Attached Files Attached Files

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

    Re: INDEX and MATCH not returning proper values

    I'm confused why it will work for 1209A but not 1209B.
    The erratic nature of a binary search algorithm on unsorted data. Sometimes the algorithm will get lucky and find itself in the "right" part of the data set. Other times it won't.

    I suspect the formula you started with will work, if you are allowed to sort the lookup data so that the 2H sets are after the 20H sets (and otherwise make sure the entire list is sorted correctly). Are you not allowed to sort the list in text sort order?

  11. #11
    Registered User
    Join Date
    12-20-2023
    Location
    Massachusetts
    MS-Off Ver
    Excel for Mac 365 vs. 16.67
    Posts
    5

    Re: INDEX and MATCH not returning proper values

    I think I found an alternative solution that will work:
    XLOOKUP(B68&"-"&C68&D68&"-"&E68&F68, $M$4:$M$1423, $N$4:$N$1423, "try again",0,-1) This will give me the very last value in the matched range.

    XLOOKUP(B68&"-"&C68&D68&"-"&E68&F68, $M$4:$M$1423, $N$4:$N$1423, "try again",0,1) This will give me the very first value in the matched range.

    Using XLOOKUP does the exact match I was hoping for. I'm still perplexed why the INDEX/MATCH broke for those values since the same circumstance works for the other examples 1209A, 1209C, and 1210A, 1210B with a similar range and order. But oh well.

    Thanks for taking your time to help me.

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,462

    Re: INDEX and MATCH not returning proper values

    See: https://support.microsoft.com/en-us/...9-88eae8bf5929

    You are choosing an exact match for your XLOOKUP. Your MATCH function is not using an Exact Match and, for that to work your data needs to be sorted.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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] Which index/match function? - matching 2 values to 2 values and returning one result
    By Wilgoss in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-10-2023, 01:35 AM
  2. Index Match returning wrong values
    By CoachK88 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-03-2018, 12:48 AM
  3. [SOLVED] Problems with INDEX, MATCH, MATCH returning incorrect values
    By Paul103 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-03-2018, 05:16 PM
  4. [SOLVED] INDEX & 2x MATCH returning incorrect values
    By Dan_B in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-06-2017, 06:01 AM
  5. [SOLVED] Index/match returning zero values ?
    By MMLBaylor in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-16-2015, 03:13 PM
  6. Index match returning incorrect values
    By Mrpussalia in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-23-2014, 10:55 PM
  7. Index and Match not returning values
    By -Spax- in forum Excel General
    Replies: 11
    Last Post: 12-06-2011, 11:29 AM

Tags for this Thread

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