Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bjulius/70025ffbfc33e6611e8ba0ef520dd2cc to your computer and use it in GitHub Desktop.
Save bjulius/70025ffbfc33e6611e8ba0ef520dd2cc to your computer and use it in GitHub Desktop.
Brian Julius M Code to Create Dynamic Holiday Table from Nager.at Public API
let
fnHolidayTable = (StartYear as number, EndYear as number, ISO2Code as text) as table =>
let
YearList = List.Numbers(StartYear, EndYear - StartYear + 1),
YearTable = Table.FromList(
YearList,
Splitter.SplitByNothing(),
{"HolYear"},
null,
ExtraValues.Error
),
APIColumn = Table.AddColumn(
YearTable,
"API",
each Web.Contents(
"https://date.nager.at/api/v3/publicholidays/" & Text.From([HolYear]) & "/" & ISO2Code
)
),
FilterHidden = Table.SelectRows(APIColumn, each [Attributes]?[Hidden]? <> true),
InvokeCustom = Table.AddColumn(FilterHidden, "Transform File", each #"Transform File"([API])),
RemoveOtherCols = Table.SelectColumns(InvokeCustom, {"Transform File"}),
Expand = Table.ExpandTableColumn(RemoveOtherCols, "Transform File", {"date", "localName", "name", "countryCode", "fixed", "global", "counties", "launchYear", "types.0"}, {"date", "localName", "name", "countryCode", "fixed", "global", "counties", "launchYear", "types.0"}),
RemoveCols = Table.RemoveColumns(Expand,{"localName", "fixed", "global", "counties", "launchYear"}),
ChangeType = Table.RenameColumns( Table.TransformColumnTypes(RemoveCols,{{"date", type date}}), {"date", "holidayDate"})
in
ChangeType
in
fnHolidayTable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment