Power Query Problems

How to Fix Power Query Row Order Changes After Expanding a Join

Elise WilliamsElise Williams Nov 2, 2026 872 views

Question details

The user needs to maintain the original row order when expanding a merged query in Excel Power Query.

How to Fix Power Query Row Order Changes After Expanding a Join
Product
Microsoft Excel (Power Query)
Device & OS
not provided
Scenario
Merging queries and expanding joined tables where the data order is critical, such as registry keys.
Observed behavior
Rows appear to change order or move after expanding a merged query due to missing matched records, disrupting the required data sequence.
Before you start

Ensure your query is fully loaded into the Power Query Editor and identify the specific 'Merged Queries' step that is causing the row order to shift.

Solution 1Recommended

Add an Index Column Before Expanding

The most reliable method to preserve row order is by adding an index column prior to the merge or expansion, which can be sorted later to restore the exact sequence.

When Power Query processes a join (merged query) where there are no matching records for the joined key, it may shift the rows upon expansion. Because Power Query relies on underlying database-like operations, row order is not guaranteed unless explicitly defined.

1
Open Power Query Editor

In Excel, navigate to the Data tab on the ribbon and click on 'Get Data', then select 'Launch Power Query Editor'.

2
Navigate to the Step Before Merge

In the Applied Steps pane on the right side of the editor, click on the step immediately preceding the 'Merged Queries' or 'Expanded...' step.

3
Add an Index Column

Go to the Add Column tab on the top ribbon, click on 'Index Column', and choose 'From 1'.

4
Perform the Expansion

Proceed with your next steps to merge and expand the columns as you originally intended.

5
Sort by Index

Click the dropdown arrow on your newly created Index column header, and select 'Sort Ascending' to restore the exact original row order.

Add an Index Column Before Expanding
Data Integrity Maintained: You can safely remove the Index column after sorting if it is no longer needed in your final data model. The established sort order will remain intact.
Free Microsoft Office alternative

Looking for a Lighter Alternative to Excel?

If complex Power Query issues and heavy Excel processing are slowing you down, try WPS Office. It provides robust spreadsheet features, excellent format compatibility, and a highly intuitive interface for your daily data analysis tasks.

  1. 1. Download WPS Office: Visit the official WPS Office website and download the free installer for your operating system.
  2. 2. Install the Software: Run the setup file and follow the quick installation prompts to set up WPS Office on your device.
  3. 3. Open Your Spreadsheets: Launch WPS Spreadsheets and open your existing .xlsx files directly without losing your data or standard formatting.
Free to download and use for essential tasksFully compatible with Microsoft Excel (.xlsx, .xls) formatsLightweight application that runs smoothly on older devicesFamiliar user interface with a quick learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Why does Power Query change row order when expanding?

Power Query treats data like a relational database table rather than a fixed spreadsheet. When merging and expanding, row order is not natively preserved because the engine optimizes the join operation, especially when there are unmatched records or null values.

Can I delete the Index column after restoring the order?

Yes. Once you have sorted the expanded table by the Index column to restore your original row order, you can add a final step to remove the Index column before loading the data back into Excel.

Does the Power Query version affect how joins are expanded?

Yes, older versions of Excel and Power Query handled expansion differently and often maintained order by default. Newer versions, including Microsoft 365, use optimized data processing engines that require explicit sorting (like using an Index) to guarantee row order.

Is there a way to avoid adding an index column?

Using an Index column is the most reliable and Microsoft-recommended method. Alternative methods involving complex M code using Table.AddColumn or buffering steps might work, but they are significantly more resource-intensive and prone to errors.