How to Fix Power Query Not Keeping Sort Order After Refresh in Excel
Question details
The user needs to ensure that data sorted by Discount Amount in descending order remains consistently sorted in the Excel output after a Power Query refresh.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Refreshing an Excel workbook containing a Power Query connected to an MS Access database.
- Observed behavior
- The intended descending sort order on the Discount Amount column is lost or overridden after the Excel output is refreshed.
Ensure your connected MS Access database is currently accessible, and verify that no hidden VBA macros are overriding your table's default sorting behavior upon refresh.
Use an Index Column to Enforce Sort Order
Adding an index column before sorting and removing it afterward forces Power Query to respect and preserve the row order.
Power Query sometimes optimizes operations by rearranging steps, which can cause sorting to be lost upon loading into Excel. By injecting an Index column, you lock the data structure in place.
In Excel, go to the 'Data' tab and click 'Get Data' > 'Launch Power Query Editor'.
Navigate to the step immediately preceding your intended sort. Go to the 'Add Column' tab on the ribbon and click 'Index Column'.
Click the dropdown arrow on your 'Discount Amount' column and select 'Sort Descending'.
Right-click the header of the newly created Index column and select 'Remove' from the context menu.
Click 'Close & Load' on the Home tab to push the correctly sorted data back to your Excel worksheet.

Clear Conflicting Worksheet-Level Sorts
Existing sort states on the destination Excel table can override the Power Query output order.
Wrap the Final Step in Table.Buffer
Using the Table.Buffer function loads the sorted table into memory, which can sometimes prevent subsequent data folding from reordering rows.
Looking for a Lighter, Faster Spreadsheet Tool? Try WPS Office
If you are dealing with complex Excel data issues or frequent slowdowns with heavy data connections, consider WPS Office. It provides a highly compatible, fast, and lightweight environment for handling daily spreadsheet tasks, data sorting, and filtering without the heavy overhead.
- 1. Download and Install: Get WPS Office for free from the official website and follow the quick installation process.
- 2. Open Your Workbooks: Open your existing .xlsx spreadsheets directly in WPS Spreadsheet without format loss.
- 3. Manage Data Easily: Use the familiar Data tab to sort, filter, and analyze your information instantly.

Frequently Asked Questions
Why does my Excel table ignore the Power Query sort order?
Excel sometimes applies a local worksheet-level sort state to the loaded Table. If the Table was previously sorted manually in the worksheet, Excel may reapply that local sort over the Power Query output immediately after a refresh.
Does Table.Buffer always fix sorting issues in Power Query?
Not always. While Table.Buffer loads the data into memory and can preserve sort order during the query evaluation, it may fail to fix the issue if the destination Excel table has conflicting settings. Adding an Index column before sorting is generally a more reliable workaround.
Can I use a VBA macro to enforce the sort after a refresh?
Yes. You can use a Worksheet_Change event or a custom RefreshAll VBA macro to automatically resort the destination table after the query finishes loading. However, this adds unnecessary complexity; it's generally best practice to handle sorting directly within Power Query using the Index column trick.




