我正在尝试使用 PowerQuery 附加来自不同工作簿的多个 Excel 表。
但是我不想手动加载每个表然后附加它们,而是想在另一个表(例如“data_sources”表)中保留工作簿名称和表及其地址的记录,以便 PowerQuery 可以知道我想要附加哪些表以及在哪里可以找到它们。
我怎样才能做到这一点?假设我有下表,稍后可以添加其他工作簿。
编辑:
以下代码将在查询结果中包含原始表中的任何新列。
#"Added Custom"
参数将创建一个包含表的列,然后在下一步中使用它来组合它们。
let
Source = Excel.CurrentWorkbook(){[Name="data_sources"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Workbook location", type text}, {"Workbook name", type text}, {"Table name", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Excel.Workbook(File.Contents([Workbook location]&[Workbook name])){[Item=[Table name],Kind="Table"]}[Data]),
#"Combine" = Table.Combine(#"Added Custom"[Custom]),
#"Filtered Rows" = Table.SelectRows(Combine, each [Client] <> null and [Client] <> "")
in
#"Filtered Rows"
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Workbook Location", type text}, {"Workbook Name", type text}, {"Table Name", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Excel.Workbook(File.Contents([Workbook Location]&[Workbook Name]) ){[Item=[Table Name],Kind="Table"]}[Data])
in
#"Added Custom"