Today I stumbled upon a neat little trick in Power BI’s Power Query Editor, and it’s too good not to share!
If you’ve ever loaded data into Power BI and ended up manually renaming columns one by one to clean them up, there’s a much faster way.
💡 You can rename all columns at once using this single line of M code:
Table.TransformColumnNames(#"Previous Step", each Text.Replace(_, " ", "_"))
This replaces all spaces in your column names with underscores, perfect for making your data model cleaner, more consistent, and coding-friendly.
🔄 Bonus: You Can Do the Reverse Too!
Want to remove underscores and make your column names more human-readable in your final dataset or report?
Just flip the logic:
Table.TransformColumnNames(#"Previous Step", each Text.Replace(_, "_", " "))
This will replace all underscores with spaces, great when you want your report visuals or exported tables to look cleaner and more natural.
✅ Why It’s Useful:
- Saves tons of time with large datasets
- Helps enforce naming consistency
- Makes your transformations more scalable and professional
Small trick, big impact. Happy data cleaning!
Ali