How to sort by multiple columns in Excel
Order a table by one column and then break ties with a second, or a third, using the Sort dialog and Add Level.
A single-column sort puts names in order or numbers from small to large. Real tables need more: group by one column, then order inside each group by another.
The Sort dialog does this with levels. The first level is the main order, and each added level breaks the ties left by the one above it.
Steps in Excel for Windows
- Click inside the table. Select any single cell in the data, or select the whole block including the header. Selecting one column alone invites trouble, because the other columns would not move with it.
- Open the Sort dialog. On the Data tab, in the Sort and Filter group, click Sort. The keyboard route is Alt, A, S, S.
- Confirm the header setting. Keep "My data has headers" ticked so the column names appear in the lists instead of Column A, Column B.
- Set the first level. Under Sort by, pick the main column, such as Dept. Leave Sort On as Cell Values and Order as A to Z.
- Add the next levels. Click Add Level, then pick Then by Sales and set Order to Largest to Smallest. Add a third level the same way if you need one.
- Click OK and check the result. Rows are ordered by the first level, and within each group by the second. If a level is in the wrong place, reopen the dialog and use the up and down arrows to reorder the levels.
Worked example
Department A to Z, then sales largest first
| A | B | C | |
|---|---|---|---|
| 1 | Dept | Name | Sales |
| 2 | Ops | Kim | 300 |
| 3 | Sales | Ana | 450 |
| 4 | Ops | Raj | 500 |
| 5 | Sales | Lee | 200 |
| 6 | Ops | Mia | 250 |
| A | B | C | |
|---|---|---|---|
| 1 | Dept | Name | Sales |
| 2 | Ops | Raj | 500 |
| 3 | Ops | Kim | 300 |
| 4 | Ops | Mia | 250 |
| 5 | Sales | Ana | 450 |
| 6 | Sales | Lee | 200 |
Dept is the first level, so the two groups come out as Ops, then Sales. Within Ops the rows run 500, 300 and 250 from largest to smallest. Within Sales they run 450 then 200. Each row moves as a whole, so every name stays beside its own figure.
Common mistakes
- Sorting one column on its own. If only column C is selected, Excel offers to expand the selection. Choosing Continue with the current selection reorders just that column and scrambles the rows. Always expand, or click one cell in the table instead.
- Header row sorted into the data. With "My data has headers" unticked, Excel sorts the header row like any other row and it lands in the middle of the table.
- Levels in the wrong order. The first level is the main sort. Putting Sales first and Dept second gives a table ordered by sales with departments only breaking exact ties, which is rarely what the prompt asked.
- Blank rows inside the data. A blank row splits the table, so only the block around the active cell is sorted. Remove blank rows first.
- Sorting formulas that use relative references. Formulas that refer to cells in other rows can return different results after a sort, because the references move with the rows. Check any total or running balance after sorting.
On Excel job tests
Wording to watch: "sort by department, then by sales from highest to lowest". The word "then" is the cue for a second level, and "highest to lowest" means Largest to Smallest. A prompt such as "sort alphabetically by last name, then first name" asks for two text levels in that order.
If the sorted table must keep working formulas, check a total after the sort. When the task asks for a separate sorted copy that updates, a formula such as SORT in Microsoft 365 does that instead.
Related guides
Questions
- How many levels can I sort by in Excel?
- Up to 64 sort levels. Most tasks need two or three.
- How do I sort by color instead of value?
- In the Sort dialog, change Sort On from Cell Values to Cell Color or Font Color, then pick which color goes on top.
- Why did my data get scrambled after sorting?
- Usually only one column was sorted, so the others stayed where they were. Press Ctrl+Z, click one cell inside the table, and sort again so the whole block moves together.
- How do I sort left to right?
- In the Sort dialog click Options and choose Sort left to right. It is for data laid out in rows instead of columns.
Practice this
The free lesson Sorting by several columns has checked exercises for this skill in a working grid.
Practice this skill