Search code examples
dategoogle-sheetsmatchgoogle-sheets-formulaweekday

Google Sheet formula to calculate nearest day of week based on date


I am trying to figure out how to best put this requirement into a formula to be used in CELL B1 in Google Sheets:

If the date in cell A1 is a Sunday or Monday, cell B1 should show that week's date for Thursday, otherwise, it should show the following week's date for Thursday.

This formula works, but seems inefficient due to its length - is there any way I could condense this?

=IF(WEEKDAY(A1)=1,A1+4,
 IF(WEEKDAY(A1)=2,A1+3,
 IF(WEEKDAY(A1)=3,A1+9,
 IF(WEEKDAY(A1)=4,A1+8,
 IF(WEEKDAY(A1)=5,A1+7,
 IF(WEEKDAY(A1)=6,A1+6,
 IF(WEEKDAY(A1)=7,A1+5,"")))))))

Solution

  • you can just use:

    =A1+MATCH(WEEKDAY(A1), {"","",2,1,7,6,5,4,3}, 0)
    

    0