Xlambda
Well-known Member
- Joined
- Mar 8, 2021
- Messages
- 860
- Office Version
- 365
- Platform
- Windows
T_US_HOLIDAY_CALC tool to calculate USA holidays. If someone needs for other country, with its specific rules let me know here.
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,{"NYD";"MLK";"WB";"MD";"ID";"LD";"CD";"VD";"TGD";"XMAS"},
CHOOSE({1,2},hd,sw)
)
)
LAMBDA 5.0.xlsm | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | |||
1 | T_US_HOLIDAY_CALC | |||||||||||||||
2 | vb.net - How to calculate holidays for the USA - Stack Overflow | |||||||||||||||
3 | For holidays on the weekend it needs to follow policy of the US government to adjust to a weekday. | |||||||||||||||
4 | If it falls on a Saturday it is adjusted to Friday. If it falls on a Sunday it needs to be adjusted to Monday. | |||||||||||||||
5 | ||||||||||||||||
6 | New Year's Day | NYD | 01-jan | 2020 | 2021 | 2022 | ||||||||||
7 | Martin Luther King Jr. | MLK | 3rd mon jan | =T_US_HOLIDAY_CALC(2020) | =T_US_HOLIDAY_CALC(21) | =T_US_HOLIDAY_CALC(22) | ||||||||||
8 | Washington´'s Birthday | WB | 3rd mon feb | NYD | 01-01-20 | NYD | 01-01-21 | NYD | 31-12-21 | |||||||
9 | Memorial Day | MD | last mon may | MLK | 20-01-20 | MLK | 18-01-21 | MLK | 17-01-22 | |||||||
10 | Independence Day | ID | 4-jul | WB | 17-02-20 | WB | 15-02-21 | WB | 21-02-22 | |||||||
11 | Labor Day | LD | 1st mon sep | MD | 25-05-20 | MD | 31-05-21 | MD | 30-05-22 | |||||||
12 | Columbus Day | CD | 2nd mon oct | ID | 03-07-20 | ID | 05-07-21 | ID | 04-07-22 | |||||||
13 | Veterans day | VD | 11-nov | LD | 07-09-20 | LD | 06-09-21 | LD | 05-09-22 | |||||||
14 | Thanksgiving day | TGD | 4th thu nov | CD | 12-10-20 | CD | 11-10-21 | CD | 10-10-22 | |||||||
15 | Christmas Day | XMAS | 25-dec | VD | 11-11-20 | VD | 11-11-21 | VD | 11-11-22 | |||||||
16 | TGD | 26-11-20 | TGD | 25-11-21 | TGD | 24-11-22 | ||||||||||
17 | XMAS | 25-12-20 | XMAS | 24-12-21 | XMAS | 26-12-22 | ||||||||||
18 | ||||||||||||||||
19 | Full example of ACALENDAR versatilyty toghether with T_FREEDAYS and T_US_HOLIDAY_CALC embedded in a single formula | |||||||||||||||
20 | -calculates the holidays that need specific calculating rules | |||||||||||||||
21 | -we can select and calculate the free weekends for the whole year, no input needed. | |||||||||||||||
22 | -we can extract working weekends exceptions | |||||||||||||||
23 | -can add another set of dates for other important dates with different icon representation | |||||||||||||||
24 | -no need to change the date manualy, if d,m,v are ignored,always updates to today() values | |||||||||||||||
25 | -regular use of any calendar for any date | |||||||||||||||
26 | ||||||||||||||||
27 | =ACALENDAR(,"nov",,T_FREEDAYS(21,{6,7},INDEX(T_US_HOLIDAY_CALC(21),,2),L32:L33),M32:M34) | |||||||||||||||
28 | Nov | 2021 | ||||||||||||||
29 | Mon | Tue | Wed | Thu | Fri | Sat | Sun | Example: | ||||||||
30 | 01 | 02 | 03 ⚠ | 04 | 05 | 06 | 07 ✔ | working | ||||||||
31 | 08 ⚠ | 09 | 10 | 11 ✔ | 12 | 13 ✔ | 14 ✔ | wknds | other dates | |||||||
32 | 15 | 16 ⚠ | 17 | 18 | 19 ? | 20 ✔ | 21 | 06-11-21 | 08-11-21 | |||||||
33 | 22 | 23 | 24 | 25 ✔ | 26 | 27 ✔ | 28 ✔ | 21-11-21 | 16-11-21 | |||||||
34 | 29 | 30 | 03-11-21 | |||||||||||||
35 | ||||||||||||||||
36 | ||||||||||||||||
T_US_HOLIDAY_CALC |
Cell Formulas | ||
---|---|---|
Range | Formula | |
E7,H7,K7,D27 | E7 | =FORMULATEXT(E8) |
E8:F17 | E8 | =T_US_HOLIDAY_CALC(2020) |
H8:I17 | H8 | =T_US_HOLIDAY_CALC(21) |
K8:L17 | K8 | =T_US_HOLIDAY_CALC(22) |
D28:J35 | D28 | =ACALENDAR(,"nov",,T_FREEDAYS(21,{6,7},INDEX(T_US_HOLIDAY_CALC(21),,2),L32:L33),M32:M34) |
Dynamic array formulas. |
Last edited by a moderator:
Upvote
0