Colin Banfield 的另一个解决方案;
1) 在 Excel 中,创建一个以年为列名的表,并输入年作为行值。然后从表中创建一个查询。您的查询应具有一列和一行值。适当地命名查询并保存。
2) 从网站获取数据。假设我们将查询命名为 HolidayTable。将查询转换为函数查询,例如
(Year as number)=>
let
Source = Web.Page(Web.Contents("www.timeanddate.com/holidays/south-africa/"&Number.ToText(Year))),
Data0 = Source{0}[Data],
#"Changed Type" = Table.TransformColumnTypes(Data0,{{"Header", type text}, {"Date", type date}, {"Weekday", type text}, {"Holiday name", type text}, {"Holiday type", type text}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Header"})
in
#"Removed Columns"
3)在步骤(1)查询中添加该函数作为新列,并添加新的日期自定义列。在进行了几次其他转换(列重新排序、列删除)之后,您应该得到一个如下所示的查询:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each HolidayTable([Year])),
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Date", "Weekday", "Holiday name", "Holiday type"}, {"Date", "Weekday", "Holiday name", "Holiday type"}),
#"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Calendar Date", each #date([Year],Date.Month([Date]),Date.Day([Date]))),
#"Reordered Columns" = Table.ReorderColumns(#"Added Custom1",{"Year", "Date", "Calendar Date", "Weekday", "Holiday name", "Holiday type"}),
#"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Year","Date"})
in
#"Removed Columns"
笔记:
a) 前两行来自步骤 (1) 中的原始表查询。
b) #"Added Custom" 步骤增加了一个新的自定义列,将Year列中的值传递给HolidayTable函数
c) #"Added Custom1" 步骤添加了一个新的自定义列,该列根据 Year 列中的值以及原始 Date 列中的月份和日期值创建新日期。