在 Power Query 中动态追加不同工作簿中的表

问题描述 投票:0回答:1

我正在尝试使用 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"
excel powerbi powerquery powerbi-desktop m
1个回答
2
投票

给定以下输入表,下面的代码可检索所有表并将它们组合起来。

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"
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.