+ Reply to Thread
Results 1 to 23 of 23

Lookup Date equal to or smaller than specified Date

  1. #1
    Registered User
    Join Date
    10-18-2017
    Location
    London
    MS-Off Ver
    Office 2016
    Posts
    11

    Lookup Date equal to or smaller than specified Date

    Hi all,

    I'm looking for assistance working out a formula that will give me a value based on looking up the last date entry equal to or before a date the user will put in. Looking at the below, if the user


    Example: User enters 02/01/2017 and result should be 4. If user enters 10/01/2017 result is 7. But if user enters 12/01/2017, it knows the last date closest to 12/01/2017 is 10/01/2017 and the answer is 7.
    A B
    01/01/2017 1
    02/01/2017 2
    02/01/2017 3
    02/01/2017 4
    05/01/2017 5
    06/01/2017 6
    10/01/2017 7

    Hope that makes sense.

    Thanks,
    NigueS

  2. #2
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Lookup Date equal to or smaller than specified Date

    With your dates in A1:A7, your numbers in B1:B7, and your lookup date in D1, try this:

    =LOOKUP(D1,A1:A7,B1:B7)

  3. #3
    Registered User
    Join Date
    10-18-2017
    Location
    London
    MS-Off Ver
    Office 2016
    Posts
    11

    Re: Lookup Date equal to or smaller than specified Date

    Thank you 63falcondude,

    Is there a formula that would work if the dates weren't in ascending order? I.e. all mixed up?

    THanks

  4. #4
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Lookup Date equal to or smaller than specified Date

    It will be less efficient, but you can use

    =LOOKUP(2,1/(A1:A7<=D1),B1:B7)

  5. #5
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Lookup Date equal to or smaller than specified Date

    Try this:

    =LOOKUP(2,1/(A$1:A$7=MAX(IF(A$1:A$7<=D1,A$1:A$7))),B$1:B$7) Ctrl Shift Enter

  6. #6
    Registered User
    Join Date
    10-18-2017
    Location
    London
    MS-Off Ver
    Office 2016
    Posts
    11
    Quote Originally Posted by Jonmo1 View Post
    It will be less efficient, but you can use

    =LOOKUP(2,1/(A1:A7<=D1),B1:B7)
    Apologies as I’m still learning these formulas by why would this be less efficient?

  7. #7
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Lookup Date equal to or smaller than specified Date

    Jonmo, would your formula work for 10/1/2017 and 12/1/2017?

    I believe that they should both result in 7 but your formula is returning 6.

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Lookup Date equal to or smaller than specified Date

    This formula
    =LOOKUP(D1,A1:A7,B1:B7)
    Does a binary lookup, that is very efficient.
    It realistically only has to actually look at a very small fraction of the cells in the range

    Doing this
    =LOOKUP(2,1/(A1:A7<=D1),B1:B7)

    This makes it look at every single cell in the range.
    Because it has to do a true/false expression (is the value in A <= D1), Then do a math operation on it as well.

    It's much more work.

    In this small sample range it won't be noticeable.
    But if your actual dataset is much larger than the sample, then you may notice the difference.
    Last edited by Jonmo1; 10-18-2017 at 01:29 PM.

  9. #9
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Lookup Date equal to or smaller than specified Date

    @63falcondude
    I get 7 for both.

    make sure you have <= not just <

  10. #10
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Lookup Date equal to or smaller than specified Date

    With the dates not in order, I get a different result.

    See attachment.
    Attached Files Attached Files

  11. #11
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Lookup Date equal to or smaller than specified Date

    I see...

    My formula is looking at the last date entered in physical order of the sheet (furthest down column A)
    Yours is looking at the last date entered chronologically

    The original post was ambiguous on the definition of 'last date entered'

  12. #12
    Registered User
    Join Date
    10-18-2017
    Location
    London
    MS-Off Ver
    Office 2016
    Posts
    11

    Re: Lookup Date equal to or smaller than specified Date

    Quote Originally Posted by 63falcondude View Post
    Try this:

    =LOOKUP(2,1/(A$1:A$7=MAX(IF(A$1:A$7<=D1,A$1:A$7))),B$1:B$7) Ctrl Shift Enter
    63falcondude.. thank you.. that works perfectly.. although I wish i new what it all meant

  13. #13
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Lookup Date equal to or smaller than specified Date

    You're welcome. Happy to help.

    I would be happy to explain how the formula works to you if you are interested.

    If that solved your question, please mark this thread as SOLVED.

    Almost forgot, welcome to the forum.

  14. #14
    Registered User
    Join Date
    10-18-2017
    Location
    London
    MS-Off Ver
    Office 2016
    Posts
    11

    Re: Lookup Date equal to or smaller than specified Date

    Thanks for all your hellp..

    Unfortunately.... I've moved the formula to an existing spreadsheet and not getting the desired result. I have the formula in the first sheet and all the dates and amounts in a second sheet. The 3rd column
    in the 2nd sheet is a running total and when there is no entry in the first two columns, it displays the last total in the 3rd column for several rows. When I enter a date that is before the earliest date,
    it should come back with a #N/A but it comes back with the last total. This does not happen on the sample sheet i produced above.

    Is there anywhere I can host the file as an example?

  15. #15
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Lookup Date equal to or smaller than specified Date

    To attach an Excel workbook, go to Go Advanced > Manage Attachments > Choose file > Upload > Close this window.

    Make sure that this workbook is representative of your actual workbook. Include the desired results from the formula/s (manually entered).
    Last edited by 63falcondude; 10-18-2017 at 03:18 PM.

  16. #16
    Registered User
    Join Date
    10-18-2017
    Location
    London
    MS-Off Ver
    Office 2016
    Posts
    11

    Re: Lookup Date equal to or smaller than specified Date

    63falcondude.. apologies but i'm looking everywhere.. but can't seem to find a heading for Advanced... ????

  17. #17
    Registered User
    Join Date
    10-18-2017
    Location
    London
    MS-Off Ver
    Office 2016
    Posts
    11

    Re: Lookup Date equal to or smaller than specified Date

    Quote Originally Posted by NiugeS View Post
    63falcondude.. apologies but i'm looking everywhere.. but can't seem to find a heading for Advanced... ????
    Found it!!! Trying to upload now.

  18. #18
    Registered User
    Join Date
    10-18-2017
    Location
    London
    MS-Off Ver
    Office 2016
    Posts
    11

    Re: Lookup Date equal to or smaller than specified Date

    I attached the file.
    Attached Files Attached Files

  19. #19
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Lookup Date equal to or smaller than specified Date

    Try this:

    =IF(F7<MIN(Bank!A3:A300),NA(),LOOKUP(2,1/(Bank!A3:A300=MAX(IF(Bank!A3:A300<=F7,Bank!A3:A300))),Bank!I3:I300))

    Adjustments to the previous formula have been marked in red.

  20. #20
    Registered User
    Join Date
    10-18-2017
    Location
    London
    MS-Off Ver
    Office 2016
    Posts
    11

    Re: Lookup Date equal to or smaller than specified Date

    Thank you very much! That works perfectly! I understand what you added but still not sure on the actual lookup...

    Thank you so much for your help!

  21. #21
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Lookup Date equal to or smaller than specified Date

    You're welcome. Basically, the LOOKUP function [ LOOKUP(2,1/... ] returns the last value in column I that meets a certain criteria.

    That criteria is: Bank!A3:A300=MAX(IF(Bank!A3:A300<=F7,Bank!A3:A300))

    So it checks the last value in the range A3:A300 that is {=MAX(IF(Bank!A3:A300<=F7,Bank!A3:A300))} and returns the corresponding value (same row) in column I.

    The MAX IF array formula finds the maximum value of A3:A300 that is less than or equal to the value in F7.

    All dates have a numerical value associated with them (the number of days away from 1/0/1900) so the MAX IF formula finds the most recent date that is less than or equal to the date in F7.

  22. #22
    Registered User
    Join Date
    10-18-2017
    Location
    London
    MS-Off Ver
    Office 2016
    Posts
    11

    Re: Lookup Date equal to or smaller than specified Date

    Thanks 63falcondude...

    Using the same spreadsheet and criteria, the above works perfectly at providing the value for the specified date. I now realise i will also need a formula to return a value when the specified date is first found (rather than last time as above). I've tried removing 2,1 etc.. but not getting the result. Could you point me in the right direction?

    Thanks again..

  23. #23
    Registered User
    Join Date
    10-18-2017
    Location
    London
    MS-Off Ver
    Office 2016
    Posts
    11

    Re: Lookup Date equal to or smaller than specified Date

    Quote Originally Posted by NiugeS View Post
    Thanks 63falcondude...

    Using the same spreadsheet and criteria, the above works perfectly at providing the value for the specified date. I now realise i will also need a formula to return a value when the specified date is first found (rather than last time as above). I've tried removing 2,1 etc.. but not getting the result. Could you point me in the right direction?

    Thanks again..
    To ensure i've explained myself correctly, if a date of 01/01/2017 is entered, the formula will first look for 01/01/2017 and return the first value for that date. If there is no entry for 01/01/2017, it will than look for the next date etc.
    Last edited by NiugeS; 10-19-2017 at 11:46 AM.

+ 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] Change code so macro activates when entry date is older or equal to current date
    By Big.Moe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-29-2017, 10:59 PM
  2. Replies: 0
    Last Post: 11-23-2015, 04:50 AM
  3. [SOLVED] Need FORMULA for Date subtract Date equal bussiness hour (don't count weekend)
    By tuongtu3 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 05-24-2015, 03:29 AM
  4. [SOLVED] Finding Largest Date but Smaller than any Given Date (non-array)
    By Jonathan78 in forum Excel General
    Replies: 10
    Last Post: 04-26-2015, 04:28 PM
  5. [SOLVED] Lookup with 3 conditons (1 is date equal or next date)
    By thilag in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-21-2014, 04:15 AM
  6. [SOLVED] Copy data from one sheet to another if the date is equal or higher than a gien date
    By ANDREAAS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-08-2013, 02:57 PM
  7. Replies: 4
    Last Post: 09-01-2011, 03:25 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