Combining multiple sheets with different columns using Power Query

ぃ、小莉子 提交于 2020-12-13 04:03:30

问题


I have a workbook with multiple pages that need to get combined, i.e. stacked, into one table. While they have many similar column names, they do not all have the same columns and the column order differs. Because of this I cannot use the inherent merge functionality because it uses column order. Table.Combine will solve the problem, but I cannot figure out to create a statement that will use the "each" mechanic to do that.

For each worksheet in x workbook Table.Combine(prior sheet, next sheet) return all sheets stacked.

Would someone please help?


回答1:


If you load your workbook with Excel.Workbook you can choose the Sheet Kind (instead of Table or DefinedName kinds) and ignore the sheet names.

let
    Source = Excel.Workbook(File.Contents("C:\Path\To\File\FileName.xlsx"), null, true),
    #"Filter Sheets" = Table.SelectRows(Source, each [Kind] = "Sheet"),
    #"Promote Headers" = Table.TransformColumns(#"Filter Sheets", {{"Data", each Table.PromoteHeaders(_, [PromoteAllScalars=true])}}),
    #"Combine Sheets" = Table.Combine(#"Promote Headers"[Data])
in
    #"Combine Sheets"



回答2:


  • Load each table into Power Query as a separate query
  • fix up the column names as needed for each individual query
  • save each query as a connection
  • in one of the queries (or in a separate query) use the Append command to append all the fixed up queries that now have the same column names.


来源:https://stackoverflow.com/questions/64900333/combining-multiple-sheets-with-different-columns-using-power-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!