Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
harry1605
Regular Visitor

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

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @harry1605 

 

As you are using Folder connector, it would be simple. In "Transform Sample File" query, Use Headers as First Row

vjingzhanmsft_0-1714116793826.png

Then Keep Top 1 Row

vjingzhanmsft_1-1714116825709.png

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!

View solution in original post

5 REPLIES 5
dufoq3
Super User
Super User

Hi @harry1605, if you upload 2 or 3 files (you can delete all the data just keep header rows and at least one data row) i.e. to google drive and provide here a link with public permissions, we can create a query for you.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

slorin
Super User
Super 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
Headers

Stéphane 

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

Anonymous
Not applicable

Hi @harry1605 

 

As you are using Folder connector, it would be simple. In "Transform Sample File" query, Use Headers as First Row

vjingzhanmsft_0-1714116793826.png

Then Keep Top 1 Row

vjingzhanmsft_1-1714116825709.png

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!

Hi Jing,

so sleek and so cool thank you.

 

Followed your instructions I had to de promote the header and take the top row and bingo got what I wanted!

 

Stephane thanks also for taking the time to support.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.