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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
mwig
New Member

How to Auto Fill Column Titles With Row Text

Hello community, 

 

I am faced with a couple hundred files which are to be imported to Power BI and I must rename the columns based on the 2rd row in each sheet. What is the best way to automate this?

 

For clarity, each sheet that I am uploading have identical templates - and each of them has the title for the columns in row 2 - and instead of copying and pasting for days - I'd like to use script that will take the text in the second row and [in the same order] rename the columns.

 

Please let me know if more information is needed!

 

Thanks!

5 REPLIES 5
ImkeF
Community Champion
Community Champion

Hi @mwig

the following function renames all columns from a table (Source) to its values from the 2nd row:

 

Table.RenameColumns(Source, List.Zip( { Table.ColumnNames(Source), List.Transform(Record.FieldValues(Source{1}), Text.From) } ))

is this what you're looking for?

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

How do I input that into the sheet? 

ImkeF
Community Champion
Community Champion

Please check out this video with instruction on how to integrate M-code into your solution: 

http://community.powerbi.com/t5/Webinars-and-Video-Gallery/Power-BI-Forum-Help-How-to-integrate-M-co...

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

When I entered the exact formula you posted it gives me an error message and then the entire sheet disappears. I'm sure I have to do some changes to the formula but why would it disable the entire sheet if I type it in wrong?

ImkeF
Community Champion
Community Champion

Sorry, but I don't understand what you mean with sheet. Could you please clarify?

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors