+ Reply to Thread
Results 1 to 12 of 12

I would like a formula to return the closest value when i don't have an exact match

  1. #1
    Forum Contributor
    Join Date
    05-30-2015
    Location
    Dubai
    MS-Off Ver
    Excel 2016 Mac & PC & 365
    Posts
    633

    I would like a formula to return the closest value when i don't have an exact match

    Hi All,

    I need a formula to return the closet value when i don't have an exact match

    Sample sheet attached

    Any help greatly appreciated

    Kevin
    Attached Files Attached Files
    Last edited by AliGW; 12-21-2016 at 01:36 PM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,312

    Re: I would like a formula to return the closet value when i don't have an exact match

    From your file:

    I would like 3999 and 4001 entered in F3 to both return 700
    Why? In any case, based on your lookup table, you can't. What is the logic for doing so?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: I would like a formula to return the closet value when i don't have an exact match

    Your example looks wrong. I assume you meant 800.

    Try this Userdefned Function

    Please Login or Register  to view this content.
    This formula will then return 800

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by mehmetcik; 12-21-2016 at 01:09 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,474

    Re: I would like a formula to return the closet value when i don't have an exact match

    We cannot change the basic search algorithms built into Excel's lookup functions. When we want a different search algorithm other than those pre-programmed for us, we must come up with our own search algorithm. In this case, I am failing to understand how you are choosing to return 700 for both 3999 and 4001. 3999 will return 700 under the usual binary algorithm (3999 will match with 3500, since it is between 3500 and 4000 in the lookup table, which then returns 700). But I do not understand why 4001 should match with 3500 (and thus return 700) and not with 4000 (and return 800 like it does).

    Is it possible that you mistyped your example? Did you intend for 3999 and 4001 to both return 800 (both match to 4000)? If that is the case, I would add a new column to my lookup table, that will compute the actual divisions that I want to use for the lookup values. Assuming I understand what "closest" means, I would expect to have lookup values of 500, 750, 1250, 1750,... (essentially the midpoints of the current divisions). Search the table based on this helper column.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Forum Contributor
    Join Date
    05-30-2015
    Location
    Dubai
    MS-Off Ver
    Excel 2016 Mac & PC & 365
    Posts
    633

    Re: I would like a formula to return the closet value when i don't have an exact match

    Quote Originally Posted by mehmetcik View Post
    Your example looks wrong. I assume you meant 800.
    Yes sorry i meant 800

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,312

    Re: I would like a formula to return the closet value when i don't have an exact match

    What is the tipping point between 3500 and 4000?

  7. #7
    Forum Contributor
    Join Date
    05-30-2015
    Location
    Dubai
    MS-Off Ver
    Excel 2016 Mac & PC & 365
    Posts
    633

    Re: I would like a formula to return the closet value when i don't have an exact match

    I am using 3750

  8. #8
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: I would like a formula to return the closet value when i don't have an exact match

    Your example looks wrong. I assume you meant 800.

    Try this Userdefned Function

    Please Login or Register  to view this content.
    This formula will then return 800

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

  9. #9
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,440

    Re: I would like a formula to return the closet value when i don't have an exact match

    You can put this array* formula in E3:

    =IF(COUNTIF(B3:B18,F3),VLOOKUP(F3,B3:C18,2,0),INDEX(C3:C18,IFERROR(MATCH(F3-MIN(ABS(B3:B18-F3)),B3:B18,0),MATCH(F3+MIN(ABS(B3:B18-F3)),B3:B18,0))))

    *NOTE: an array formula needs to be committed using the key combination of Ctrl-Shift-Enter (CSE) rather than the usual < Enter >.

    Any value in F3 between 3251 and 3750 (inclusive) will return 700, values between 3751 and 4250 will return 800, and so on.

    Another (simpler) way, as you have increments of 500 between the values in column B, is to use this non-array version:

    =IF(COUNTIF(B3:B18,F3),VLOOKUP(F3,B3:C18,2,0),VLOOKUP(F3+250,B3:C18,2,1))

    though this will match between 3250 and 3749 (you can adjust the 250 in red to affect this behaviour).

    Hope this helps.

    Pete

  10. #10
    Forum Contributor
    Join Date
    05-30-2015
    Location
    Dubai
    MS-Off Ver
    Excel 2016 Mac & PC & 365
    Posts
    633

    Re: I would like a formula to return the closet value when i don't have an exact match

    Thank you all for your help, I used Pete's array suggestion

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,312

    Re: I would like a formula to return the closest value when i don't have an exact match

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  12. #12
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,440

    Re: I would like a formula to return the closest value when i don't have an exact match

    Because of the regularity of your data, you can also use this formula to give the same results as the array formula:

    =MROUND(F3-1,500)*0.2

    If you want the equivalent of the second formula that I gave you, just remove the -1.

    Hope this helps.

    Pete

+ 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. Replies: 1
    Last Post: 09-07-2016, 09:27 AM
  2. [SOLVED] Return value on multiple criteria without an exact match
    By Caco in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-27-2015, 04:29 PM
  3. To Sort exact and partial exact match for a single column.
    By Jagdev in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-22-2014, 05:08 AM
  4. Comparing two text columns and return data based on an exact match
    By AShah33 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-04-2013, 04:23 PM
  5. [SOLVED] 2 References to match and Return an Exact Value
    By cychua in forum Excel General
    Replies: 18
    Last Post: 10-09-2012, 06:12 AM
  6. Find Closet Match in a table
    By Chompy in forum Excel General
    Replies: 4
    Last Post: 04-20-2012, 08:36 AM
  7. Replies: 2
    Last Post: 12-09-2011, 07:17 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