Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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!
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?
Please check out this video with instruction on how to integrate M-code into your solution:
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?
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
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!