Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateJoin 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.
Have you worked with an Excel or CSV file that changes slightly their column names? Whatever the reason, this seems to make your Power BI refresh crash.
As you know, Power Query is very susceptible to any change, especially using Functions such as Table.ReorderColumns or Table.SelectRows.
To solve that problem we have developed a function called ColumnStandardizer. The idea as the name suggests is to standardize a set of columns from a given table based on a list of predefined columns.
Assuming receiving a monthly table like the one below.
The column headers are roughly the same, but rarely are exactly the same, so appending a folder will not work as expected.
Standard Names
The first step is to decide on the standard names of your columns. We have defined the ones for the table above.
That means we have removed unnecessary characters and added a space for clarity.
Steps
To simplify the code I’ve used Source = Table.
let Source = Table, GetColumnNames = Table.ColumnNames(Source), RenameList = ColumnStandardizer( GetColumnNames, {"Date Period", "Date Time", "Sales Amount", "Profit Amount"} ), ReplaceColumnNames = Table.RenameColumns(Source, RenameList) in ReplaceColumnNames
The second argument of ColumnStandardizer defines the standard list of columns {"Date Period", "Date Time", "Sales Amount", "Profit Amount"}. This can be also defined in a Power Query variable as we did.
The same example as before, the only difference is we have an additional column we weren’t expecting, Margin.
Date.Period Date.Time Sales.Amount Profit_Amount Margin
Well, that’s not a problem. We can do the same we did before, and we just need to add an additional step with Table.SelectColumns.
Basically, because we have standardised the column names, and we have defined that list beforehand, we use the list again in Table.SelectColumns
let Source = Table, GetColumnNames = Table.ColumnNames(Source), StandardColumns = {"Date Period", "Date Time", "Sales Amount", "Profit Amount"}, RenameList = ColumnStandardizer(GetColumnNames, StandardColumns), ReplaceColumnNames = Table.RenameColumns( Source, ColumnStandardizer( GetColumnNames, {"Date Period", "Date Time", "Sales Amount", "Profit Amount"} ) ), SelectColumns = Table.SelectColumns(ReplaceColumnNames, StandardColumns) in SelectColumns
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
8 | |
6 | |
6 | |
5 | |
5 |
User | Count |
---|---|
10 | |
8 | |
6 | |
6 | |
6 |