+ Reply to Thread
Results 1 to 6 of 6

Thread: Find the nearest value from an Array

  1. #1
    Registered User
    Join Date
    10-23-2010
    Location
    Hyderabad
    MS-Off Ver
    Excel 2003
    Posts
    43

    Find the nearest value from an Array

    Hi All,
    I need help with the formula which will show the nearest value from an array for an Id. I have attached the sample worksheet.

    An agent will login multiple times in a day, i want to know what is the nearest login time.

    Thanks in Advance

    Regards,
    Anto
    Attached Files Attached Files
    Last edited by anto1510; 01-01-2012 at 04:32 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    455

    Re: Find the nearest value from an Array

    Assumme A10 content ID,
    =LOOKUP(2,IF(A2:A8=A10,1,""),D2:D8)
    Confirmed with Ctrl-Shift-Enter

  3. #3
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Find the nearest value from an Array

    Assuming D to be your expected results:

    D2:
    =SUM(IF($A$2:$A$8=$A2,IF(ABS($C$2:$C$8-$B2)=MIN(IF($A$2:$A$8=$A2,ABS($C$2:$C$8-$B2))),$C$2:$C$8)))
    confirmed with CTRL + SHIFT + ENTER
    copied down
    I am sure with more thought it could be condensed.



    @bebo021999 - though not relevant to the answer here you could remove the Array in your example:

    =LOOKUP(2,1/(A2:A8=A10),D2:D8)
    confirmed with Enter
    one of the advantages of LOOKUP is that you can generally avoid Array entry by virtue of lookup vector.

  4. #4
    Registered User
    Join Date
    10-23-2010
    Location
    Hyderabad
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Find the nearest value from an Array

    wow DonkeyOte, you are awesome.

    I have attached one more sample sheet, this includes Date and also time. can you please help ?

    Thanks in Advance

    Regards,
    Anto
    Attached Files Attached Files

  5. #5
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Find the nearest value from an Array

    The same formula should work - you need simply amend ranges accordingly - though D3 should read 12/27/2011 12:14 AM I think ?

    In XL Dates are Integers whereas Time is Decimal (1 = 24 hours, 0.5 = 12 hours etc...).
    Given the above you can perform mathematical calculations with dates and time as you would with numbers in general.

  6. #6
    Registered User
    Join Date
    10-23-2010
    Location
    Hyderabad
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Find the nearest value from an Array

    Thank you so much.

+ 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.2.0