Hi @wynn,
Here’s what I did, I created 2 separate queries one for 2022 and one for 2023 using the From Web connector. Looking at the Html.Table code you will notice a difference:
Html.Table(Source, {{“Column1”, "DIV:nth-child(8) …
Html.Table(Source, {{“Column1”, "DIV:nth-child(10) …
Just include an if-statement to deal with that:
( Year as number ) as table =>
let
Source = Web.BrowserContents("https://www.calendarpedia.com/holidays/federal-holidays-"&Number.ToText(Year)&".html"),
FromHtml = [
a = Html.Table(Source, {{"Column1", "DIV:nth-child(8) > TABLE:nth-child(7) > * > TR > :nth-child(1)"}, {"Column2", "DIV:nth-child(8) > TABLE:nth-child(7) > * > TR > :nth-child(2)"}, {"Column3", "DIV:nth-child(8) > TABLE:nth-child(7) > * > TR > :nth-child(3)"}}, [RowSelector="DIV:nth-child(8) > TABLE:nth-child(7) > * > TR"]),
b = Html.Table(Source, {{"Column1", "DIV:nth-child(10) > TABLE:nth-child(7) > * > TR > :nth-child(1)"}, {"Column2", "DIV:nth-child(10) > TABLE:nth-child(7) > * > TR > :nth-child(2)"}, {"Column3", "DIV:nth-child(10) > TABLE:nth-child(7) > * > TR > :nth-child(3)"}}, [RowSelector="DIV:nth-child(10) > TABLE:nth-child(7) > * > TR"]),
c = if Table.RowCount(a) =0 then b else a
][c],
ChType = Table.TransformColumnTypes(FromHtml,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),
DelTopRow = Table.Skip(ChType,1),
DelBottomRow = Table.RemoveLastN(DelTopRow,1),
PromoteHeaders = Table.PromoteHeaders(DelBottomRow, [PromoteAllScalars=true]),
ChType2 = Table.TransformColumnTypes(PromoteHeaders,{{"Date", type date}, {"Federal holiday", type text}, {"Day of the week", type text}}),
SelRows = Table.SelectRows(ChType2, each ([Day of the week] <> "Saturday" and [Day of the week] <> "Sunday")),
ReplaceValue = Table.ReplaceValue(SelRows,"(observed)","",Replacer.ReplaceText,{"Federal holiday"}),
ReplaceValue2 = Table.ReplaceValue(ReplaceValue,"*","",Replacer.ReplaceText,{"Federal holiday"}),
SelCols = Table.SelectColumns(ReplaceValue2,{"Date", "Federal holiday"})
in
SelCols
I hope this is helpful