How to Sort by Two Columns in Excel and Keep Rows Together
Group orders by team and sort the largest quantities first within each team. Use a record check to make sure every ID stays with its original quantity.
Follow these steps at your own pace. Check product terms and prices directly with providers before purchasing.
Quick answer
Select the full block of data, including its headers. In desktop Excel, open Data → Sort and check My data has headers. Choose the first column, click Add Level and choose the second column. Click OK once to apply both rules to the whole selection.
1. Choose the entire list before sorting
In A1:C1 enter Team, Order and Units. In row 2 enter East, A10 and 4. In row 3 enter West, A11 and 12. In row 4 enter East, A12 and 9. Jot down one complete record to check later. For example, A10 belongs to East and has four units.
Select A1:C4. On a larger worksheet, include every column that belongs to the records, even a notes column across a blank spacer. Leave unrelated totals and side tables outside the selection. Save a copy first if you need to recover the original order.
2. Set the main grouping
On the Data tab choose Sort to open the dialog. When Excel warns that nearby data is outside the selection, choose Expand the selection if all those cells belong to the list. Otherwise cancel and select the exact rectangle yourself. Check My data has headers. Under Sort by, choose Team, leave Sort On at Cell Values, then choose A to Z.
3. Choose the order within each team
Click Add Level. In the Then by row, choose Units, Cell Values and Largest to Smallest. Team should appear above Units in the dialog. Click OK. Both East orders should appear before the West order, even though West has the largest single quantity.
4. Verify a full row and the order of the groups
Compare your result with the table. Find A10 and confirm it still has East and 4 beside it. If that combination has changed, press Ctrl+Z immediately. Check the selection before trying again. Sorting one column by itself can separate an order from its original details.
| Team | Order | Units |
|---|---|---|
| East | A12 | 9 |
| East | A10 | 4 |
| West | A11 | 12 |
Why is the numeric order wrong?
If Excel offers only alphabetic sort choices for Units, the quantities may be stored as text. Test a sample with =ISNUMBER(C2). Convert text quantities to numbers before sorting again. Keep codes such as 00127 as text when the leading zeros are meaningful.
Microsoft Support · Sort data in a range or table in Excel
Comments
Read or join the discussion.