Trouble adapting T_US_HOLIDAY_CALC Lambda

jdellasala

Well-known Member
Joined
Dec 11, 2020
Messages
751
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. 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:
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)
    )
)
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!
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)
    )
)
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 Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How about
Excel Formula:
=LAMBDA([y],
    LET(y,IF(ISOMITTED(y),YEAR(TODAY()),y),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)
    )
)
 
Upvote 0
Solution
How about
Excel Formula:
=LAMBDA([y],
    LET(y,IF(ISOMITTED(y),YEAR(TODAY()),y),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)
    )
)
THANK YOU!!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

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