Forum Discussion
Append multiple workbooks by column position not by headers
- Anonymous4 years ago
You can just Demote Headers, then combine, nice and easy.
Hi Rahul_SC ,
Please see below code combine files with different column header name but same column position:
let
// Replace blue text with your folder path
Source = Folder.Files("C:\Users\cktan\Documents\PQ Training"),
RemoveHiddenFiles = Table.SelectRows(Source, each not Text.Contains([Name],"~")),
//FirstN formula to get the first row (that's the first file on the list and header only)
GetHdrs = Table.FirstN(Table.AddColumn(RemoveHiddenFiles, "GetTbl", each Table.FirstN(Excel.Workbook([Content]){[Kind = "Sheet"]}[Data],1)),1),
//Skip formula skip the row, in this case I skip 1 to exclude the headers
GetTbls = Table.AddColumn(RemoveHiddenFiles, "GetTbl", each Table.Skip(Excel.Workbook([Content]){[Kind = "Sheet"]}[Data],1)),
//Combine Hdr and Data(No header)
CombineHdrs2Tbls = Table.Combine({GetHdrs,GetTbls}),
//Expand Data
GetTbl = Table.Combine(CombineHdrs2Tbls[GetTbl]),
#"Promoted Headers" = Table.PromoteHeaders(GetTbl, [PromoteAllScalars=true])
in
#"Promoted Headers"
Workbook for below code:
Combine Files with different header but same column position
Regards
KT
Hi,
I did it as you suggested, but getting this error.
- KT_Bsmart2gethe4 years ago
Impactful Individual
Hi Rahul_SC ,
Which step will it takes you to if you click on the "Go to Error"?
GetHdrs step:
You should expect something like this.
GetTbl Step:
You should expect something like this.
CombineHdrs2Tbls step:
You should expect something like this.
Once we are able to get it works, it should run it dynamically.
Regards
Kerwin