Power Query Problems

How to Fix Power Query Not Keeping Sort Order After Refresh in Excel

Anum MushtaqAnum Mushtaq Oct 28, 2026 868 views

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.

How to Preserve Power Query Sort Order After 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.
Before you start

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.

Solution 1Recommended

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.

1
Open Power Query Editor

In Excel, go to the 'Data' tab and click 'Get Data' > 'Launch Power Query Editor'.

2
Add an Index Column

Navigate to the step immediately preceding your intended sort. Go to the 'Add Column' tab on the ribbon and click 'Index Column'.

3
Apply Your Sort

Click the dropdown arrow on your 'Discount Amount' column and select 'Sort Descending'.

4
Remove the Index Column

Right-click the header of the newly created Index column and select 'Remove' from the context menu.

5
Load the Query

Click 'Close & Load' on the Home tab to push the correctly sorted data back to your Excel worksheet.

Use an Index Column to Enforce Sort Order
Sorting Context Locked: This method establishes a strict sequence of operations, preventing Excel from discarding your sort order during a data refresh.
Free Microsoft Office alternative

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. 1. Download and Install: Get WPS Office for free from the official website and follow the quick installation process.
  2. 2. Open Your Workbooks: Open your existing .xlsx spreadsheets directly in WPS Spreadsheet without format loss.
  3. 3. Manage Data Easily: Use the familiar Data tab to sort, filter, and analyze your information instantly.
Fully compatible with Microsoft Excel (.xlsx, .xls, .csv) file formats.Lightweight installation that opens large datasets quickly and smoothly.Built-in advanced formulas, pivot tables, and intuitive data sorting capabilities.Familiar interface that guarantees a seamless transition with zero learning curve.
microsoft office alternative - wps office

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.