Return first Monday in April from one date and first Monday in current year April if another is blank

SaraWitch

Active Member
Joined
Sep 29, 2015
Messages
322
Office Version
  1. 365
Platform
  1. Windows
Hello peeps,

I call upon your expertise again!

I have a start date in A2 and an end date in B2. I want a formula in C2 to return the first Monday in April before the A2 date. I also want a formula in D2 (E2 from example below) to return the date of the first Monday in April of the current year if no date is entered in B2 but to return the date in B2 if one is entered.

For example:
Auto move row.xlsm
ABCDE
1Start DateEnd DateFirst Monday in April before Start DateI can get first Monday in month, but not April'sFirst April Monday in Current Year if B2 empty or B2 date
211/11/2023Should be 03/04/202306/11/2023Should be 03/04/2023
310/10/2021Should be 05/04/202104/10/2021Should be 03/04/2023
403/01/2024Should be 03/04/202301/01/2024Should be 03/04/2023
512/12/202210/10/2023Should be 04/04/202205/12/2022Should be 10/10/2023
604/04/2022Should be 04/04/202204/04/2022Should be 03/04/2023
703/04/2022Should be 05/04/202104/04/2022Should be 03/04/2023
802/02/202304/04/2023Should be 03/04/202306/02/2023Should be 04/04/2023
929/09/202203/01/2024Should be 04/04/202205/09/2022Should be 03/01/2024
1029/09/2022Should be 04/04/202205/09/2022Should be 03/04/2023
Sheet3
Cell Formulas
RangeFormula
D2:D10D2=IF(A2=0,"",A2-DAY(A2)+8-WEEKDAY(A2-DAY(A2)+6))
Cells with Data Validation
CellAllowCriteria
A1:E10Any value


I can return the first Monday of a date's month (column D), but not April's. I've also tried breaking down the dates into years first, but I'm ending up with more columns than I feel I need.

Any help would be gratefully received. :)
 
Try the following
Check the logic very carefully since the challenge seemed to evolve.

T202401a.xlsm
ABCD
1Start DateEnd DateFormula Fiscal Year Start Date (first Monday in April)Formula Fiscal Year End Date (first Monday in April)
202-Apr-23Mon 04-Apr-22Mon 03-Apr-23
303-Apr-22Mon 05-Apr-21Mon 03-Apr-23
403-Apr-2204-Apr-22Mon 05-Apr-21Mon 04-Apr-22
502-Apr-22Mon 05-Apr-21Mon 03-Apr-23
602-Apr-2203-Apr-22Mon 05-Apr-21Mon 05-Apr-21
702-Apr-2203-Apr-23Mon 05-Apr-21Mon 03-Apr-23
801-Apr-25Mon 01-Apr-24Mon 03-Apr-23
901-Apr-2508-Apr-25Mon 01-Apr-24Mon 07-Apr-25
1b_4
Cell Formulas
RangeFormula
C2:C9C2=LET(yc,WORKDAY.INTL(DATE(YEAR(A2),4,0),1,"0111111"),yp,WORKDAY.INTL(DATE(YEAR(A2)-1,4,0),1,"0111111"),IF(A2<=yc,yp,yc))
D2:D9D2=LET(yc,WORKDAY.INTL(DATE(2023,4,0),1,"0111111"),yx,WORKDAY.INTL(DATE(YEAR(A2)-1,4,0),1,"0111111"),yp,WORKDAY.INTL(DATE(YEAR(B2),4,0),1,"0111111"),IF(B2<1,yc,IF(AND(B2>=yx,B2<yp),yx,yp)))
 
Upvote 0
Solution

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
A different approach that you can consider.

Cell Formulas
RangeFormula
H2:H9H2=LOOKUP(A2,$K$1:$K$9,$K$1:$K$9)
I2:I9I2=IF(B2,LOOKUP(B2,$K$1:$K$9,K$1:$K$9),$K$4)
K1:K9K1=WORKDAY.INTL(DATE(2020+ROW()-1,4,0),1,"0111111")


or


T202401a.xlsm
ABHI
1Start DateEnd Date
202-Apr-23Mon 04-04-22Mon 03-04-23
303-Apr-22Mon 05-04-21Mon 03-04-23
403-Apr-2204-Apr-22Mon 05-04-21Mon 04-04-22
502-Apr-22Mon 05-04-21Mon 03-04-23
602-Apr-2203-Apr-22Mon 05-04-21Mon 05-04-21
702-Apr-2203-Apr-23Mon 05-04-21Mon 03-04-23
801-Apr-25Mon 01-04-24Mon 03-04-23
901-Apr-2508-Apr-25Mon 01-04-24Mon 07-04-25
10
1b_4
Cell Formulas
RangeFormula
H2:H9H2=LET(b,{43927;44291;44655;45019;45383;45754;46118;46482;46846},LOOKUP(A2,b,b))
I2:I9I2=LET(b,{43927;44291;44655;45019;45383;45754;46118;46482;46846},IF(B2,LOOKUP(B2,b,b),45019))
 
Last edited:
Upvote 1
If the above works for you and If you do not want to see the details of the formula,
you can build your own function with Excel 365.
With Name Manager, Name the function something appropriate and user friendly and
put the Lambda details in the value area.

T202401a.xlsm
ABHI
1Start DateEnd Date
202-Apr-23Mon 04-04-22Mon 03-04-23
303-Apr-22Mon 05-04-21Mon 03-04-23
403-Apr-2204-Apr-22Mon 05-04-21Mon 03-04-23
502-Apr-22Mon 05-04-21Mon 03-04-23
602-Apr-2203-Apr-22Mon 05-04-21Mon 03-04-23
702-Apr-2203-Apr-23Mon 05-04-21Mon 03-04-23
801-Apr-25Mon 01-04-24Mon 03-04-23
901-Apr-2508-Apr-25Mon 01-04-24Mon 03-04-23
10
1b_4
Cell Formulas
RangeFormula
H2:H9H2=StartD(A2)
I2:I9I2=EndD(B2)
Lambda Functions
NameFormula
EndD=LAMBDA(EndDateCell,LET(s,EndDateCell,b,{43927;44291;44655;45019;45383;45754;46118;46482;46846},IF('1b_4'!XEV1,LOOKUP('1b_4'!XEV1,b,b),45019)))
StartD=LAMBDA(Start,LET(s,Start,b,{43927;44291;44655;45019;45383;45754;46118;46482;46846},LOOKUP(s,b,b)))
 
Upvote 1
The copy shown in post #23 should be as follows


T202401a.xlsm
ABHI
1Start DateEnd Date
202-Apr-23Mon 04-04-22Mon 03-04-23
303-Apr-22Mon 05-04-21Mon 03-04-23
403-Apr-2204-Apr-22Mon 05-04-21Mon 04-04-22
502-Apr-22Mon 05-04-21Mon 03-04-23
602-Apr-2203-Apr-22Mon 05-04-21Mon 05-04-21
702-Apr-2203-Apr-23Mon 05-04-21Mon 03-04-23
801-Apr-25Mon 01-04-24Mon 03-04-23
901-Apr-2508-Apr-25Mon 01-04-24Mon 07-04-25
1b_4
Cell Formulas
RangeFormula
H2:H9H2=StartD(A2)
I2:I9I2=EndD(B2)
Lambda Functions
NameFormula
EndD=LAMBDA(EndDateCell,LET(s,EndDateCell,b,{43927;44291;44655;45019;45383;45754;46118;46482;46846},IF(s,LOOKUP(s,b,b),45019)))
StartD=LAMBDA(Start,LET(s,Start,b,{43927;44291;44655;45019;45383;45754;46118;46482;46846},LOOKUP(s,b,b)))
 
Upvote 0
Oh my goodness, Dave!!

Your solution in post #21 worked perfectly!

I shall also explore your other solutions, that are great learning opportunities (I'd never heard of LAMBDA, which looks great too!). I have a LOOKUP for the fiscal year elsewhere which I was considering for the fiscal date, but this is amazing!

I do thank you for the time you have spent on this, Dave - I am (still!) in awe and very grateful 🙏🙇‍♀️😍
 
Upvote 0
Thanks for the feedback.
If you want to try the Lambda, try the example. If you want additional information, please advise.
N.B. You can customize the terminology etc. for your environment.
Consider
- how to make function use-friendly (name for function, name(s) for input, ...)
- the Lambda states the inputs required
- how to adapt it for the next fiscal year
 
Upvote 1
T202401a.xlsm
ABCDEFGHIJKLMN
1 -- V1 with Lookup table -- -- V2 without Lookup table -- -- V3 with Lambda --YE startYE EndText
2Start DateEnd DateFor Column A, Day 1 of YE For Column B, Day 1 of: if blank Current YE if Date of that dateMon Apr 6, 2020Sun Apr 4, 2021Mon Apr 6, 2020 to Sun Apr 4, 2021
302-Apr-2304-Apr-2203-Apr-2304-Apr-2203-Apr-2304-Apr-2203-Apr-23Mon Apr 5, 2021Sun Apr 3, 2022Mon Apr 5, 2021 to Sun Apr 3, 2022
403-Apr-2205-Apr-2103-Apr-2305-Apr-2103-Apr-2305-Apr-2103-Apr-23Mon Apr 4, 2022Sun Apr 2, 2023Mon Apr 4, 2022 to Sun Apr 2, 2023
503-Apr-2204-Apr-2205-Apr-2104-Apr-2205-Apr-2104-Apr-2205-Apr-2104-Apr-22Mon Apr 3, 2023Sun Mar 31, 2024Mon Apr 3, 2023 to Sun Mar 31, 2024
602-Apr-2205-Apr-2103-Apr-2305-Apr-2103-Apr-2305-Apr-2103-Apr-23Mon Apr 1, 2024Sun Apr 6, 2025Mon Apr 1, 2024 to Sun Apr 6, 2025
702-Apr-2203-Apr-2205-Apr-2105-Apr-2105-Apr-2105-Apr-2105-Apr-2105-Apr-21Mon Apr 7, 2025Sun Apr 5, 2026Mon Apr 7, 2025 to Sun Apr 5, 2026
802-Apr-2203-Apr-2305-Apr-2103-Apr-2305-Apr-2103-Apr-2305-Apr-2103-Apr-23Mon Apr 6, 2026Sun Apr 4, 2027Mon Apr 6, 2026 to Sun Apr 4, 2027
901-Apr-2501-Apr-2403-Apr-2301-Apr-2403-Apr-2301-Apr-2403-Apr-23Mon Apr 5, 2027Sun Apr 2, 2028Mon Apr 5, 2027 to Sun Apr 2, 2028
1001-Apr-2508-Apr-2501-Apr-2407-Apr-2501-Apr-2407-Apr-2501-Apr-2407-Apr-25Mon Apr 3, 2028Sun Apr 1, 2029Mon Apr 3, 2028 to Sun Apr 1, 2029
11Mon Apr 2, 2029Sun Mar 31, 2030Mon Apr 2, 2029 to Sun Mar 31, 2030
12Mon Apr 1, 2030Sun Apr 6, 2031Mon Apr 1, 2030 to Sun Apr 6, 2031
13Mon Apr 7, 2031Sun Apr 4, 2032Mon Apr 7, 2031 to Sun Apr 4, 2032
14Mon Apr 5, 2032Sun Apr 3, 2033Mon Apr 5, 2032 to Sun Apr 3, 2033
15Mon Apr 4, 2033Sun Apr 2, 2034Mon Apr 4, 2033 to Sun Apr 2, 2034
16Mon Apr 3, 2034Sun Apr 1, 2035Mon Apr 3, 2034 to Sun Apr 1, 2035
17Mon Apr 2, 2035Sun Apr 6, 2036Mon Apr 2, 2035 to Sun Apr 6, 2036
18Mon Apr 7, 2036Sun Apr 5, 2037Mon Apr 7, 2036 to Sun Apr 5, 2037
19Mon Apr 6, 2037Sun Apr 4, 2038Mon Apr 6, 2037 to Sun Apr 4, 2038
20Mon Apr 5, 2038Sun Apr 3, 2039Mon Apr 5, 2038 to Sun Apr 3, 2039
21Mon Apr 4, 2039Sun Apr 1, 2040Mon Apr 4, 2039 to Sun Apr 1, 2040
22Mon Apr 2, 2040Sun Mar 31, 2041Mon Apr 2, 2040 to Sun Mar 31, 2041
23
1bb
Cell Formulas
RangeFormula
K2:K22K2=WORKDAY.INTL(DATE(2020+SEQUENCE(21,,0,1),4,0),1,"0111111")
L2:L22L2=WORKDAY.INTL(DATE(2020+SEQUENCE(21,,1,1),4,0),1,"0111111")-1
C3:C10C3=LOOKUP(A3,YE_Day1)
D3:D10D3=IF(B3,LOOKUP(B3,YE_Day1),LOOKUP(TODAY(),YE_Day1))
E3E3=LET(YE_Day1,WORKDAY.INTL(DATE(2020+SEQUENCE(21,,0,1),4,0),1,"0111111"),LOOKUP(A3,YE_Day1))
F3F3=LET(YE_Day1,WORKDAY.INTL(DATE(2020+SEQUENCE(21,,0,1),4,0),1,"0111111"),IF(B3,LOOKUP(B3,YE_Day1),LOOKUP(TODAY(),YE_Day1)))
G3:G10G3=FYE_Day1(A3)
H3:H10H3=FYE_Day1_CurrentYEor(B3)
E4:E10E4=LET(x,WORKDAY.INTL(DATE(2020+SEQUENCE(21,,0,1),4,0),1,"0111111"),LOOKUP(A4,x))
F4:F10F4=LET(YE_Day1,WORKDAY.INTL(DATE(2020+SEQUENCE(21,,0,1),4,0),1,"0111111"),IF(B4="",LOOKUP(TODAY(),YE_Day1),LOOKUP(B4,YE_Day1)))
N2:N22N2=TEXT(K2,"ddd mmm d, yyyy")&" to "&TEXT(L2,"ddd mmm d, yyyy")
Dynamic array formulas.
Named Ranges
NameRefers ToCells
YE_Day1='1bb'!$K$2:$K$22C3:D10, N2
Lambda Functions
NameFormula
FYE_Day1=LAMBDA(cellrefDate,LET(d,cellrefDate,YE_Day1,WORKDAY.INTL(DATE(2020+SEQUENCE(21,,0,1),4,0),1,"0111111"),LOOKUP(d,YE_Day1)))
FYE_Day1_CurrentYEor=LAMBDA(cellrefDate,LET(d,cellrefDate,YE_Day1,WORKDAY.INTL(DATE(2020+SEQUENCE(21,,0,1),4,0),1,"0111111"),IF(d,LOOKUP('1bb'!XFA1,YE_Day1),LOOKUP(TODAY(),YE_Day1))))
 
Upvote 0
Wow! This is incredible and has really inspired me to explore Excel further (I may even look at some advanced training!). I bow to your prowess, Dave! ☺️
 
Upvote 0
Thanks very much; I really appreciate your comments and I am glad that you reviewed alternative with Excel.

I noticed that the post did not include an edit. I renamed the function and included the edit.

T202401a.xlsm
ABGH
1 -- V3 with Lambda --
2Start DateEnd Date
302-Apr-2304-Apr-2203-Apr-23
403-Apr-2205-Apr-2103-Apr-23
503-Apr-2204-Apr-2205-Apr-2104-Apr-22
602-Apr-2205-Apr-2103-Apr-23
702-Apr-2203-Apr-2205-Apr-2105-Apr-21
802-Apr-2203-Apr-2305-Apr-2103-Apr-23
901-Apr-2501-Apr-2403-Apr-23
1001-Apr-2508-Apr-2501-Apr-2407-Apr-25
11
1bb
Cell Formulas
RangeFormula
G3:G10G3=FYE_Day1(A3)
H3:H10H3=FYE_B(B3)
Lambda Functions
NameFormula
FYE_B=LAMBDA(cellrefDate,LET(d, cellrefDate, YE_Day1, WORKDAY.INTL(DATE(2020 + SEQUENCE(21, , 0, 1), 4, 0), 1, "0111111"), IF(d = "", LOOKUP(TODAY(), YE_Day1, YE_Day1), LOOKUP(d, YE_Day1, YE_Day1))))
FYE_Day1=LAMBDA(cellrefDate,LET(d,cellrefDate,YE_Day1,WORKDAY.INTL(DATE(2020+SEQUENCE(21,,0,1),4,0),1,"0111111"),LOOKUP(d,YE_Day1)))
 
Upvote 1

Forum statistics

Threads
1,215,073
Messages
6,122,974
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top