+ Reply to Thread
Results 1 to 7 of 7

Find correct start date

  1. #1
    Registered User
    Join Date
    01-05-2009
    Location
    Southern Pines, NC
    MS-Off Ver
    Excel 2007
    Posts
    95

    Find correct start date

    I am trying to add a formula that will look to a row of dates and return the most recent date that is less than today. For example, say there is a list of paydates and I want to return the most recent. How can this be accomplished.

    In the attached, I want the formula in cell D2. Today, it should return 6/27/14, but if the file opens a week from today, then it should return 7/11/14.Excel Forum.xlsx
    Last edited by mjhopler; 07-10-2014 at 03:20 PM.

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find correct start date

    Using your posted file...and assuming the Pay Dates will be in ascending order,
    this formula returns the next previous pay date
    Please Login or Register  to view this content.
    EDITED TO INCLUDE THIS VARIATION:
    If the formula needs to reference blank cells below the Pay Dates list,
    use this formula:
    Please Login or Register  to view this content.
    If today is 09-Jul-2014, that formula returns: 27-Jun-2014

    Is that something you can work with?
    Last edited by Ron Coderre; 07-09-2014 at 03:42 PM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    01-05-2009
    Location
    Southern Pines, NC
    MS-Off Ver
    Excel 2007
    Posts
    95

    Re: Find correct start date

    These work perfect! Now, can you help me understand why?

    For the 1st one:
    Can you explain why the 1/... part? This portion is the lookup_vector which i understand to mean this is the section is it looking to match the value to return the result_vector. Therefore, the A2:A15 makes sense to me, but i don't follow the 1/ or how Toda() being here works (I do know what the Today() function is).

    For the 2nd one:
    How does the multiplication come into play?

    Thank your for your help!

  4. #4
    Registered User
    Join Date
    01-05-2009
    Location
    Southern Pines, NC
    MS-Off Ver
    Excel 2007
    Posts
    95

    Re: Find correct start date

    Looking at this further, the way I would read this is:

    Return the value that is less than 2 using range A2:A12 when the numbers in this range are 1 divided by the value, but exclude values greater than today.

    If the above is correct, why does the following not work?

    =LOOKUP(TODAY(),(A2:A12<TODAY()),A2:A12)

    I would read this as return the value that is less than today using range A2:A12, but excluding values greater than today.

  5. #5
    Registered User
    Join Date
    01-05-2009
    Location
    Southern Pines, NC
    MS-Off Ver
    Excel 2007
    Posts
    95

    Re: Find correct start date

    Sorry for the multiple posts, but trying to understand.

    Taking this one step further, the following does work, so why add the extra coding?

    =LOOKUP(TODAY(),A2:A15,A2:A15)

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find correct start date

    I'll use this formula: =LOOKUP(2,1/((A2:A15<>"")*(A2:A15<TODAY())),A2:A15)
    because it addresses both questions

    First, when the LOOKUP function is searching for a value that is larger than all of the lookup_range values, it returns the LAST value of the same type (numeric, in this case)

    Second, this section: (A2:A15<>"")
    test if the referenced cells are not blank and returns an array of TRUE/FALSE values
    Example: {TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE}

    Third, this section: (A2:A15<TODAY())
    tests if the dates in the referenced cells are less than today and returns an array of TRUE/FALSE values
    Example: {TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE}

    Fourth, when a boolean (TRUE/FALSE) value is impacted by an arithmetic operation (+, -, *, /)
    TRUE becomes 1 and FALSE becomes 0

    When we multiply those two arrays:

    {TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE}
    X
    {TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE}
    becomes: {1,1,1,1,1,0,0,0,0,0,0,0,0,0}

    By dividing those results into 1, we get this result:
    {1,1,1,1,1,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!}

    We end up with either 1's or errors.

    Now this formula:
    =LOOKUP(2,1/((A2:A15<>"")*(A2:A15<TODAY())),A2:A15)
    resolves to this:
    =LOOKUP(2,{1,1,1,1,1,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!},A2:A15)

    Since the 2 is larger than the 1's, LOOKUP will match on the LAST numeric 1 and return the corresponding value from A2:A15

    I hope that helps.
    Last edited by Ron Coderre; 07-10-2014 at 04:19 PM.

  7. #7
    Registered User
    Join Date
    01-05-2009
    Location
    Southern Pines, NC
    MS-Off Ver
    Excel 2007
    Posts
    95

    Re: Find correct start date

    You are Awesome!!!

+ 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: 2
    Last Post: 12-09-2013, 06:21 AM
  2. [SOLVED] Find start and end date of the last 5 quarters
    By grsnipe in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-16-2013, 01:49 PM
  3. [SOLVED] Find start date and end date for the employee
    By Solomon14all in forum Excel General
    Replies: 2
    Last Post: 09-29-2012, 12:46 AM
  4. [SOLVED] Find date using start date and number of network days
    By v!ctor in forum Excel General
    Replies: 4
    Last Post: 07-06-2012, 05:27 PM
  5. Replies: 2
    Last Post: 01-04-2012, 09:15 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