Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Google Sheets – search within a list of dates and find the next closest future date

Question:

Given a list of pay periods and sales dates. For each sales date, determine the next pay day.

Pay periods (given) Sale date (given) Pay day (To be generated)
June 4 June 4 June 4
June 17 June 4 June 4
June 30 June 4 June 4
July 15 June 5 June 17
June 5 June 17
June 12 June 17
June 16 June 17
June 18 June 30
June 22 June 30
June 24 June 30
June 28 June 30
June 30 June 30
July 1 July 15
July 7 July 15
July 8 July 15
July 9 July 15
July 10 July 15

Google Sheets: Yellow = given data, Blue = answer to be generated


Clostest I’ve gotten:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

=arrayformula(filter($A$2:$A,abs($A$2:$A-B2)=min(abs($A$2:$A-B2))))

This formula is incorrect as for some of the sales date, the pay day is earlier. The sale date must always come before the pay day because in real life, you’re only paid after you make a sale, not before.

>Solution :

I’m a fan of SQL, so here’s an intuitive solution using QUERY():

=QUERY(A:A, "
    SELECT 
        A 
    WHERE 
        A >= DATE '"&TEXT(B2, "yyyy-mm-dd")&"' 
    ORDER BY 
        A 
    LIMIT 
        1 
    LABEL 
        A ''
    "
    , 1)

I threw it in your Google Sheet so you can see it in action!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading