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
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
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
Thank you, it helped. But there is a problem i am facing. I want to add File Name in a column as well as we added sheet name. it will be easier for me to give reference to. Kindly respond at earliest.