Why Excel Totals Change After Sorting Data and How to Fix It
Question details
The user is experiencing an issue where SUM and AVERAGE total values change unexpectedly after sorting a dataset.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Sorting a dataset that contains formulas pulling data from another table or utilizing AVERAGE calculations.
- Observed behavior
- The total calculations change their values because the sorting operation causes the relative cell references in the formulas to shift incorrectly.
Before modifying your formulas, press Ctrl + Z to undo the sort, returning your data to its original state so you can safely audit the references.
Lock Formula References Using Absolute Cell References
Convert relative cell references to absolute references so they do not shift when data rows move during a sort.
When you sort data in Excel, formulas with relative references (like A1) automatically update based on their new row position. If your formula pulls data from another table, this shifting causes calculation errors and changes your totals.
Click on the cell in the 'Hours' column (or any affected column) that contains the formula changing after the sort.
Click into the Formula Bar at the top of the worksheet to edit the formula.
Highlight the cell references pointing to the external table and press F4 on your keyboard. This adds dollar signs to the reference (e.g., changing B2 to $B$2), locking it in place.
Press Enter to save the formula, then double-click the fill handle in the bottom-right corner of the cell to apply the locked formula down the column before sorting again.

Use Direct Functions and Structured References
Recreate the calculations using direct functions like AVERAGE or utilize Excel Table structured references to prevent shifting.
Prevent Calculation Errors Easily with WPS Spreadsheet
WPS Spreadsheet provides intuitive formula auditing tools and seamless data sorting. You can easily lock cell references to keep your totals accurate, with full compatibility for Microsoft Excel files.
- 1. Open Your Document: Launch WPS Spreadsheet and open the document where the totals are changing.
- 2. Audit the Formula: Double-click the cell containing the formula that references external data to enter editing mode.
- 3. Lock the Reference: Highlight the cell reference in the formula bar and press F4 to make it an absolute reference with dollar signs.
- 4. Sort Data Safely: Navigate to the Data tab and choose Sort. Your data will reorder without affecting the calculated totals.

Frequently Asked Questions
Why do my formulas break when I sort data in Excel?
Formulas break during sorting if they use relative references (like C2). When the row moves, Excel automatically updates the reference, which can point to the wrong data. Using absolute references (like $C$2) prevents this shifting.
Can I sort data without affecting the SUM formula at the bottom?
Yes. If your SUM formula is at the bottom of the data range, ensure it is not included in the sort selection. Select only the data rows above the total row before clicking the Sort button.
How do I lock a cell reference before sorting?
Double-click the cell to edit the formula, place your cursor on the cell reference you want to lock, and press the F4 key on your keyboard. This inserts dollar signs (e.g., $A$1), which locks both the column and row.




