jdellasala
Well-known Member
- Joined
- Dec 11, 2020
- Messages
- 755
- Office Version
- 365
- Platform
- Windows
- Mobile
- Web
A post by Xlambda presented a wonderful LAMBDA function that provides the dates for holidays for a given year. It results in a two column array with Holiday abbreviations in the first column, and dates for those holidays in the second column - something especially useful for those .INTL date functions. I didn't care for the abbreviations, and had no problem adapting it to provide full holiday names instead:
However, I also wanted to adapt to make the y parameter optional, and if not provided simply use YEAR(TODAY()) as the value of y. Simple enough I THOUGHT!, but I've tried adding a simple IF clause to the function, but it doesn't work at all!
That yields a #VALUE! error, adding a comma after the IF statement just yields "You've entered too few arguments..." error and the formula can't be entered, putting the IF statement as the first LET variable " y, IF(y=0, YEAR(TODAY()), y)," yields a #CALC! error.
I'm stumped! I've always had problems with optional parameters. Can someone show me what the problem is?
Thanks!
Excel Formula:
=LAMBDA(y,
LET(f,EDATE("1-1-"&y,0),fs,f-WEEKDAY(f,3),s,SEQUENCE(54,7,fs),m,INDEX(s,,1),
mm,MONTH(m),mlk,XLOOKUP(1,mm,m)+14,wb,XLOOKUP(2,mm,m)+14,md,XLOOKUP(5,mm,m,,,-1),ld,XLOOKUP(9,mm,m),cd,XLOOKUP(10,mm,m)+7,th,INDEX(s,,4),mth,MONTH(th),tgd,XLOOKUP(11,mth,th)+21,
xd,DATE(YEAR(f),{1;7;11;12},{1;4;11;25}),wd,WEEKDAY(xd,3),yd,IF(wd=6,xd+1,IF(wd=5,xd-1,xd)),
sw,SWITCH(SEQUENCE(10),1,INDEX(yd,1),2,mlk,3,wb,4,md,5,INDEX(yd,2),6,ld,7,cd,8,INDEX(yd,3),9,tgd,10,INDEX(yd,4)),
hd,{"New Year's Day";"Martin Luther King Day";"President's Day";"Memorial Day";"Fourth of July";"Labor Day";"Columbus Day";"Veteran's Day";"Thanksgiving Day";"Christmas Day"},
CHOOSE({1,2},hd,sw)
)
)
Excel Formula:
=LAMBDA([y], IF(y=0, y=YEAR(TODAY()), y)
LET( f,EDATE("1-1-"&y,0),fs,f-WEEKDAY(f,3),s,SEQUENCE(54,7,fs),m,INDEX(s,,1),
mm,MONTH(m),mlk,XLOOKUP(1,mm,m)+14,wb,XLOOKUP(2,mm,m)+14,md,XLOOKUP(5,mm,m,,,-1),ld,XLOOKUP(9,mm,m),cd,XLOOKUP(10,mm,m)+7,th,INDEX(s,,4),mth,MONTH(th),tgd,XLOOKUP(11,mth,th)+21,
xd,DATE(YEAR(f),{1;7;11;12},{1;4;11;25}),wd,WEEKDAY(xd,3),yd,IF(wd=6,xd+1,IF(wd=5,xd-1,xd)),
sw,SWITCH(SEQUENCE(10),1,INDEX(yd,1),2,mlk,3,wb,4,md,5,INDEX(yd,2),6,ld,7,cd,8,INDEX(yd,3),9,tgd,10,INDEX(yd,4)),
hd,{"New Year's Day";"Martin Luther King Day";"President's Day";"Memorial Day";"Fourth of July";"Labor Day";"Columbus Day";"Veteran's Day";"Thanksgiving Day";"Christmas Day"},
CHOOSE({1,2},hd,sw)
)
)
I'm stumped! I've always had problems with optional parameters. Can someone show me what the problem is?
Thanks!