Forum Discussion
Combine all sheets with different names from multiple files
- 5 years ago
Hello Anonymous
read from a folder, where you have all your files. On the folder data add this formula (hopefully you are reading from a sheet and not from a table, otherwise you would need to adapt the code a little bit
Table.Combine( List.Transform( Excel.Workbook([Content])[Data], each Table.PromoteHeaders(_)))this formula gives you combines tables form every single file. Right click on your step on the right side and choose insert step after. User here now again a table.combine where you are reference your previous step and your newly created column
Table.Combine(#"Added Custom"[TablesFromFile])here a complete example
let Source = Folder.Files("YourFolderWithFilesToMerge"), #"Added Custom" = Table.AddColumn(Source, "TablesFromFile", each Table.Combine( List.Transform( Excel.Workbook([Content])[Data], each Table.PromoteHeaders(_)))), CombineAllFiles = Table.Combine(#"Added Custom"[TablesFromFile]) in CombineAllFilesCopy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy - 5 years ago
Hello Anonymous
this code now adds the sheet name before combining
let Source = Folder.Files("YourFolderWithFilesToMerge"), #"Added Custom" = Table.AddColumn(Source, "TablesFromFile", each Table.Combine(Table.AddColumn(Excel.Workbook([Content]), "WithSheetName", (add)=> Table.AddColumn(Table.PromoteHeaders(add[Data]),"Sheet name", each add[Name] ))[WithSheetName])), CombineAllFiles = Table.Combine(#"Added Custom"[TablesFromFile]) in CombineAllFilesCopy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hi AlB,
Thank you for the reply.
I have no problem to merge multiple worksheets from a single file, but my problem is to merge multiple files that each with multiple worksheets with different name.
Then the second file will be ComB BankA USD and etc.
Hello Anonymous
read from a folder, where you have all your files. On the folder data add this formula (hopefully you are reading from a sheet and not from a table, otherwise you would need to adapt the code a little bit
Table.Combine( List.Transform( Excel.Workbook([Content])[Data], each Table.PromoteHeaders(_)))
this formula gives you combines tables form every single file. Right click on your step on the right side and choose insert step after. User here now again a table.combine where you are reference your previous step and your newly created column
Table.Combine(#"Added Custom"[TablesFromFile])
here a complete example
let
Source = Folder.Files("YourFolderWithFilesToMerge"),
#"Added Custom" = Table.AddColumn(Source, "TablesFromFile", each Table.Combine( List.Transform( Excel.Workbook([Content])[Data], each Table.PromoteHeaders(_)))),
CombineAllFiles = Table.Combine(#"Added Custom"[TablesFromFile])
in
CombineAllFiles
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
- Anonymous5 years agoNot applicable
Thank you very much! It works