Forum Discussion
Just taking first row
Hello
I have a number of files in a folder and wanted to know how I could in power query
- only take the first (header row) from each file into a single file. I want to do this so that I can compare the headers in each file
- automate the process
Thanks
- Anonymous2 years ago
Hi harry1605
As you are using Folder connector, it would be simple. In "Transform Sample File" query, Use Headers as First Row.
Then Keep Top 1 Row.
Then go to the combined query, if there is a step called "Changed Type", remove this step. You will have all column headers in the combined query.
Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!
5 Replies
- slorinSuper User
Hi,
with csv files
let
Source = Folder.Files("C:\Temp"),
csv_files = Table.SelectRows(Source, each [Extension] = ".csv"),
Headers = Table.Combine(
Table.AddColumn(
csv_files,
"Header",
each Table.FromRecords({[Name = [Name]] & Csv.Document([Content],null,";"){0}})
)[Header])
in
HeadersStéphane
- harry1605Regular Visitor
Hi Stephane,
Thank you for your response. I am new to power query so can I confirm the following is correct or if you can correct for me:
1. I have opened a new excel workbook and selected get data from folder and have chosen the combine and transform option
2. When in the power query editor I go to the transform file step (or is it another step or way) I replace from the let statement with your code - my files are xlsx so replace csv
Thanks
- AnonymousNot applicable
Hi harry1605
As you are using Folder connector, it would be simple. In "Transform Sample File" query, Use Headers as First Row.
Then Keep Top 1 Row.
Then go to the combined query, if there is a step called "Changed Type", remove this step. You will have all column headers in the combined query.
Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!