Reordering columns in Power Query without errors

Here you can find easy-to-apply steps that will help you with changing data sources and reordering columns steps.

As you probably know, your query can have only one reorder step, at the end for example. All reordering steps can be deleted once you finish building your query.

There is a risk that your query will crash and return an error, once your source with for example month/year in the column name will change. The error will be displayed, once only one or more columns won’t be found in your source.

How to avoid that and prepare a query for extending sources with applied desired reordering? Just change your last reordering step with the below code and your column names in the ColumnNames step.

ColumnNames = {"ID","2022.11", "2022.12", "2022.10", "2023.01", "2023.02", "2023.03", "2023.04", "2023.05", "2023.06", "2023.07", "2023.08", "2023.09", "2023.10", "2023.11", "2023.12", "Comment"},

ExistingColumns = Table.ColumnNames(PreviousStepName),
ColumnsToReorder = List.Intersect({ColumnNames, ExistingColumns}),

ReorderedColumns = Table.ReorderColumns(PreviousStepName, ColumnsToReorder)

In
ReorderedColumns


Leave a comment

About Me

As a power platform fan and developer of solutions that can help in daily tasks, I have a deep understanding of how technology can be leveraged to make everyday work more efficient and effective. With a passion for automation and optimization, I am always looking for new ways to streamline processes and save time. I have a strong knowledge of the power platform, including Power Apps, Power BI, and Power Automate, and I am skilled in creating custom solutions to solve specific business needs. My expertise and enthusiasm for the power platform make me an invaluable asset to any organization looking to enhance their productivity and streamline their workflows.

Newsletter

Design a site like this with WordPress.com
Get started