Forum Discussion
MaL60903280
8 months agoNew Member
Remove Top Row not applied to multiple files when using get data from folder
Hi, I have tried to combine several files (in the same format) from a folder and to use " remove top row" and "use first row as header". However, after I "close & load", only the first file has ...
- 8 months ago
Hi MaL60903280 Thanks for asking questions.
Since you do not mentiond file types, here are two source m-code for excel and csv files.
Go to Transform Data and use it, you just need to change the file path location:
Excel:
let Source = Folder.Files("C:\Users\RejaulIslamRoyel\Desktop\data"), #"Filtered Files" = Table.SelectRows(Source, each [Extension] = ".xlsx"), #"Process Files" = Table.Combine( List.Transform( #"Filtered Files"[Content], each let // Open the Excel workbook Workbook = Excel.Workbook(_, null, true), // Get the first sheet (adjust if needed) FirstSheet = Workbook{0}[Data], // Skip top row(s) and promote headers SkipRows = Table.Skip(FirstSheet, 1), PromoteHeaders = Table.PromoteHeaders(SkipRows, [PromoteAllScalars=true]) in PromoteHeaders ) ) in #"Process Files"for CSV Files:
let Source = Folder.Files("C:\Users\RejaulIslamRoyel\Desktop\data"), #"Filtered Files" = Table.SelectRows(Source, each [Extension] = ".csv"), #"Process Files" = Table.Combine( List.Transform( #"Filtered Files"[Content], each Table.PromoteHeaders( Table.Skip(Csv.Document(_, [Delimiter=",", Encoding=1252]), 1), [PromoteAllScalars=true] ) ) ) in #"Process Files"Find this helpful? ✔ Give a Kudo • Mark as Solution – help others too!
I’d love to stay connected. Join me on LinkedIn for more tips, learning paths, and real-world Fabric & Power BI solutions.
Olufemi7
7 months agoSuper User
Hi MaL60903280,
Apply your steps in the Transform Sample File query. That query is the template Power Query uses to process every file in the folder.
If you only apply changes in the combined output query, they’ll affect just the first file.
See Microsoft’s docs: Combine files overview