请参考上面的图片链接
我在一个文件夹中有多个文件xlsx
。每个文件只有一张。(文件中显示了示例4个源文件),带有文件名。
每个文件都有前n行作为交易数据(10-100行之间的n行是不固定的)。
底部是交易摘要。(第一行未固定,未固定项目)
我仅使用powerquery
来查找文件名所有项目的摘要。
问题:我的摘要行有时从10有时32起,有时是100开始加星号。它没有固定,因此无法编码。
答案 0 :(得分:0)
这将为每个文件在“总计摘要”行下查找数据,然后将每个工作簿中的数据组合在一起:
查询:fnWeeklySummary
(Workbook, Week) =>
let
Source = Excel.Workbook(Workbook, null, true),
Worksheet = Source{0}[Data],
#"Added Index" = Table.AddIndexColumn(Worksheet, "Index", 1, 1),
#"Rows To Skip" = Table.SelectRows(#"Added Index", each Text.Contains([Column1], "Total Summary"))[Index]{0},
#"Skipped Rows" = Table.Skip(Worksheet,#"Rows To Skip"),
#"Promoted Headers" = Table.PromoteHeaders(#"Skipped Rows", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"SKU", type text}, {"Inventory", Int64.Type}, {"Sellin", Int64.Type}, {"Ratio", Percentage.Type}}),
#"Added Week" = Table.AddColumn(#"Changed Type", "Week", each Week, type text),
#"Reordered Columns" = Table.ReorderColumns(#"Added Week",{"Week", "SKU", "Inventory", "Sellin", "Ratio"})
in
#"Reordered Columns"
查询:每周数据
let
Source = Folder.Files("D:\WeeklyData"),
#"Invoked Custom Function" = Table.AddColumn(Source, "Summary Data", each fnWeeklySummary([Content], Text.Replace([Name], ".xlsx", ""))),
#"Combined Summary Data" = Table.Combine(#"Invoked Custom Function"[Summary Data])
in
#"Combined Summary Data"