How to Fix Power Query Row Order Changes After Expanding a Join
Question details
The user needs to maintain the original row order when expanding a merged query in Excel Power Query.

- 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.
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.
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.
In Excel, navigate to the Data tab on the ribbon and click on 'Get Data', then select 'Launch Power Query Editor'.
In the Applied Steps pane on the right side of the editor, click on the step immediately preceding the 'Merged Queries' or 'Expanded...' step.
Go to the Add Column tab on the top ribbon, click on 'Index Column', and choose 'From 1'.
Proceed with your next steps to merge and expand the columns as you originally intended.
Click the dropdown arrow on your newly created Index column header, and select 'Sort Ascending' to restore the exact original row order.

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. Download WPS Office: Visit the official WPS Office website and download the free installer for your operating system.
- 2. Install the Software: Run the setup file and follow the quick installation prompts to set up WPS Office on your device.
- 3. Open Your Spreadsheets: Launch WPS Spreadsheets and open your existing .xlsx files directly without losing your data or standard formatting.

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.




