+ Reply to Thread
Results 1 to 16 of 16

Lookup for 4 criteria and retrieve the nearest match

  1. #1
    Registered User
    Join Date
    01-22-2019
    Location
    turkey
    MS-Off Ver
    2016
    Posts
    10

    Lookup for 4 criteria and retrieve the nearest match

    hey guys,

    I have 2 lists of items, consisting of 4 values (in column b,c,d and e). What I want to do is to find matches between sheets. Usually I use concatenate to group the all criteria i need to check, then i proceed. But there are no matches for most of the cases. for these ones, i just want to find the nearest matching values for column c,d and e from list 2 sheet into corresponding item in list 1 sheet.

    I have found examples with 2 criteria, but i am not able to modify these INDEX and MATCH formulas for more criteria.

    * first it should find an exact match for B column value from "list 2" sheet.

    * if there is a match for data in B column from "list 2" sheet with specific corresponding cell in "list 1", formula should check for an exact match of C column. If there are no matches in C column between the corresponding cells, it should pick the nearest bigger match from "list 2" sheet.

    * The process should continue for D and E columns with preference of exact matches, but ok to be picked the nearest bigger values.

    * The most important point is all the picked items' concatenated version should already be existing in A column in second sheet. It should retrieve the item from A column from sheet 2 to sheet 1 with maximum similarity, and if available it should return with exact match.

    to make it more clear, as long as it is available in A column from second sheet, it should pick an exact match for B, then C has the priority over D and E. It should select the item row in that order "Exact (B) > Nearest (C) > Nearest (D) = Nearest (E)" and retrieve the corresponding matching data from A column of that row from secondary sheet to first sheet.

    Can anybody help me about this issue? any idea will be appreciated. file is attached for reference.

    Thanks in advance.

    * this question is also asked on reddit with title of: "lookup_for_4_criteria_and_retrieve_the_nearest". I am not able to post URLs as i am new on this forum.

    Edited by GK. Here is the link:

    https://www.reddit.com/r/excel/comme...e_the_nearest/
    Attached Files Attached Files
    Last edited by Glenn Kennedy; 01-18-2021 at 03:49 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Lookup for 4 criteria and retrieve the nearest match

    slayerweb,

    If there is no exact match, what happens if one column is close but not another? (e.g record on sheet 2 has a close match in Col D but no other column, whilst another has a close match in Col C but no other)
    Do you want the nearest "cubed" match (L x H x W)? Or four lots of "closest matches" to each record? Or are you giving priorities to one column over another (e.g. find closest match to Col B, if none then closest to Col C, etc)?

    Ochimus

  3. #3
    Registered User
    Join Date
    01-22-2019
    Location
    turkey
    MS-Off Ver
    2016
    Posts
    10

    Re: Lookup for 4 criteria and retrieve the nearest match

    Hi Ochimus,

    Sorry, i should be more clear. I will explain what i expect below:

    * first it should find an exact match for B column value from "list 2" sheet.

    * if there is a match for data in B column from "list 2" sheet with specific corresponding cell in "list 1", formula should check for an exact match of C column. If there are no matches in C column between the corresponding cells, it should pick the nearest bigger match from "list 2" sheet.

    * The process should continue for D and E columns with preference of exact matches, but ok to be picked the nearest bigger values.

    * The most important point is all the picked items' concatenated version should already be existing in A column in second sheet. It should retrieve the item from A column from sheet 2 to sheet 1 with maximum similarity, and if available it should return with exact match.

    As a brief answer to your question,

    as long as it is available in A column, it should pick an exact match for B, then C has the priority over D and E. It should select the item row in that order "Exact (B) > Nearest (C) > Nearest (D) = Nearest (E)" and retrieve the corresponding matching data from A column of that row.

    Thank you for your interest, hope that i was clear this time to explain what i need.

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: Lookup for 4 criteria and retrieve the nearest match

    With more than 200 rows (a sample need not exceed 20 rows to facilitate checking), I have not checked this. However, I have added a column to show whether the match was exact or Approx>=.

    A few rows of expected answers, manually calculated, would also have helped (as well as a smaller sample!!), as I am guessing what you want to see. But check this over.

    =IFERROR(INDEX('list 2'!$A$2:$A$252,MATCH(1,INDEX(('list 2'!$B$2:$B$252='list 1'!B2)*('list 2'!$C$2:$C$252>='list 1'!C2)*('list 2'!$D$2:$D$252>=D2)*('list 2'!$E$2:$E$252>=E2),0),0)),"")

    In Turkey, you may need to use ; instead of ,
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  5. #5
    Registered User
    Join Date
    01-22-2019
    Location
    turkey
    MS-Off Ver
    2016
    Posts
    10

    Re: Lookup for 4 criteria and retrieve the nearest match

    Hi Glenn,

    I am sorry for the length of my list, I just copied my workbook and did not thought of shortening it. Also i will be sure about expected answers and manual calculations will be added in my future questions.

    Your solution works like a charm, but there is only one issue about it. for D and E columns, as formula is with >=, it is not finding a match at all in some cells. is there any way to modify this formula for D and E columns for "just match with nearest" logic instead of "match with the equal and bigger values"? IE in 17th row, we got a blank result just for E value is 2310 and is not able to match with 2300.

    thank you again and again for your help.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: Lookup for 4 criteria and retrieve the nearest match

    I'll take another look. However, I forgot to tell you that I had to SORT the source data as well to get it working. So nearest matching... above OR below??

  7. #7
    Registered User
    Join Date
    01-22-2019
    Location
    turkey
    MS-Off Ver
    2016
    Posts
    10

    Re: Lookup for 4 criteria and retrieve the nearest match

    yes, to get it work, nearest matching. I would prefer bigger values and mentioned like that but i was not aware that i was leading to a dead-end, so any matches below or above is fine with me.
    and thank you again. =)
    Last edited by slayerweb; 01-17-2021 at 09:56 AM. Reason: better explanation

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: Lookup for 4 criteria and retrieve the nearest match

    Welcome (back) to the forum.

    Thanks for your question. However, we have just found out that you have posted the same question elsewhere.... and haven't told us. Feel free to cross-post on other sites...

    But. Every forum has its rules. Please see Forum Rule #3 about cross-posting. So.

    Do not keep it a secret. We all are willing to give you our time, freely. However, it can be very annoying if we waste our time developing a solution for you, when you already have a nice solution elsewhere. All we ask is that you show us some respect and tell us:

    1) if you have cross-posted, and

    2) the URL of the cross posts.

    That way, those of us who don't want to waste their time can quickly check to see if you're already happy with another solution.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)

  9. #9
    Registered User
    Join Date
    01-22-2019
    Location
    turkey
    MS-Off Ver
    2016
    Posts
    10

    Re: Lookup for 4 criteria and retrieve the nearest match

    I edited my initial post to include the information i've additionally given and include the information that it is posted on somewhere else too. However as I am new on the forum, i am not allowed to share an URL yet.

    sorry for not reading forum rules.

  10. #10
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: Lookup for 4 criteria and retrieve the nearest match

    Thanks for providing the link.

    We are not quite there yet, as I don't think you have defined your priority clearly enough. I suspect that this is likely to prove too complicated for my tiny brain. but, we will see.

    I have created 5 Dynamic Named ranges (on top of the thousands of others that you have there already!!).

    They are: All, Type, FR, Height & Width. They come in two sorts, depending on whether the values are NUMBERS or text. The Text ones look like this:

    ='list 2'!$A$2:INDEX('list 2'!$A:$A,MATCH("Zzzz",'list 2'!$A:$A))

    and the number ones like this:

    ='list 2'!$C$2:INDEX('list 2'!$C:$C,MATCH(1E+100,'list 2'!$C:$C))

    They will automatically adjust the ranges passed on to the formula to align with the data Table in List2.

    In List1, F2, I used this to return EXACT matches:
    =IFERROR(INDEX(All,MATCH(1,INDEX((Type=$B2)*(FR=$C2)*(Width=$D2)*(Height=$E2),0),0)),"")

    In List 1, G2, I used this to return NEAREST match to FR, irrespective of the values of Height & Width. I didn't check it too closely (too many rows for much manual checking), but this MAY return silly matches that are wayyy out.

    In List 1, H2, i did the same returning NEAREST match to Width, irrespective of the values of FR & Height.

    Finally in List 1, I2, I did the same thing again, returning NEAREST match to Height, irrespective of the values of FR & Width.

    So in column F, you have the best match possible. In G, H and I you have up to 3 possible answers.

    HOWEVER. I strongly suspect that what you REALLY want is something that minimises the differences for ALL 3 parameters combined. If so, you will need to describe with 120% clarity how that needs to be done (mathematically, not in Excel terms).
    Attached Files Attached Files

  11. #11
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Lookup for 4 criteria and retrieve the nearest match

    Glenn,

    It's obviously slayerweb's choice, but the mathematical option I raised in Post#2 of choosing the nearest "cubed" match (L x H x W) minimises the differences in all three paramaters combined.

    Ochimus
    Last edited by Ochimus; 01-18-2021 at 01:09 PM.

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: Lookup for 4 criteria and retrieve the nearest match

    Thanks, Ochimus... I missed that comment. Easy enough to implement... well within our "pay grade", as they say. We'll see what happens if/when he comes back.

  13. #13
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: Lookup for 4 criteria and retrieve the nearest match

    Ochimus, I had also thought of a simple sum of the absolute deviations (L+W+H) or a "weighting" the three variable parameters (e.g. x 1 for length, x 0.5 for width and x 0.25 for height)... varying the weight in accordance with the OP's apparent L>W>H priority expressed somewhere (Here? Reddit?) a bit earlier; and then summing them.

    Who knows...

  14. #14
    Registered User
    Join Date
    01-22-2019
    Location
    turkey
    MS-Off Ver
    2016
    Posts
    10

    Re: Lookup for 4 criteria and retrieve the nearest match

    Hi Ochimus and Glenn,
    I am grateful for your valuable helps, especially Glenn's formulas in last workbook will be very useful for me to understand the logic for this kind of issues.
    I am a lil bit alien for the terms and logic that you are using, so sometimes i find it hard to understand and explain what i aim. I am just a architect who has not struggled with mathematical equations so much. I am fascinated by excel's (in fact mathematics') endless possibilities to express/solve your problems.
    And thank you again Glenn, even if it was not the exact solution to my problem (because of i was not clear enough), the last workbook that you have sent was more than enough to get a result; i just manually picked from the narrowed down options that you've provided.
    If it is ok with you, before marking this thread as solved, I just want to keep this post a little more alive just to understand how this "dark magic" works and help to develop a better solution for others that may refer to.
    If it will not be too much, could you please explain me some points that i have no clue what is going on?
    *I guess i need to "concatenate" in a way to relate these L W H data each other to start, what is the difference in approach between making it as (L x W x H) or (L + W + H)?
    *As far as I understood, weighting is about multiplying the values according to their priorities in the equation. i can see the reason of "why" but i have no idea about "how" it works.

    My questions may be too elementary for the complexity of the things that you are dealing with, if so please let me know so that i will mark the thread as solved.

  15. #15
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,023

    Re: Lookup for 4 criteria and retrieve the nearest match

    I can explain the formula, once we agree the formula. See the attached sheet. Hopefully, if you answer the Qs correctly, I can reach a fimal result.

    1. Does it matter if the measurements are GREATER than the specification or LESS than the specification? If it does not matter and your answer will be NO, it does matter, answer YES and tell me which is more important. More tolerance for values GREATER or more tolerance for values LESS. I think that I understand that the direction of the variance is not important.


    2. Is one parameter more important than another? If which one(s) and by how much. In the sample file, I have made L the most important, followed by W (5 times less important than L) follwed by H (25 times less important than L). If there is a differenc ein priority, fill in the values in F4 to H4. If they are all equally important, leave these cells blank. These cells do not "do" anything yet. They are for information only.

    3. I have populated a table with the LWH values for MD-04. (B8 to D46). In cells G8 to I8 and dnown, enter some real life choices that you have to make. Then look down the LWH values and manually choose the best fit in your judgement and enter the option number in J8. Continue until you get bored!! I will then review this to try to see if i can detect a pattern to your choices.
    Attached Files Attached Files

  16. #16
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Lookup for 4 criteria and retrieve the nearest match

    If C>D>E is the priotity order, try to assign them with their own weighting by: C*100+D*10+E for both range ,then subtract:
    ABS((('list 2'!$C$2:$C$252*100+'list 2'!$D$2:$D$252*10+'list 2'!$E$2:$E$252)-($C2*100+$D2*10+$E2))
    then get the smallest

    and the final formula:

    Exact match, F2:

    Please Login or Register  to view this content.
    nearest match , G2:

    Please Login or Register  to view this content.
    Quang PT

+ 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. Look up using two pieces of criteria but need the nearest match
    By bigbavarian in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-17-2021, 12:13 PM
  2. [SOLVED] Help, Match and Retrieve on criteria....
    By AshleyB2912 in forum Excel General
    Replies: 15
    Last Post: 06-03-2016, 10:34 AM
  3. Index Match with Multiple Criteria One to Nearest Date
    By burningeagle in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-16-2014, 11:59 AM
  4. lookup or match - Return nearest match
    By devouk in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-05-2012, 06:11 AM
  5. Lookup nearest Value in one Column and Match the next Collumn
    By tomlancaster in forum Excel General
    Replies: 4
    Last Post: 10-27-2009, 07:38 AM
  6. [SOLVED] Lookup nearest value (Index & Match)
    By [email protected] in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-06-2006, 12:35 PM
  7. [SOLVED] How can I retrieve multiple rows that match one criteria, i.e. a d
    By Duke Carey in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 09-06-2005, 05:05 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