Excel guide · 6 min read
How to sort by multiple columns in Excel
=SORTBY(A2:E10,B2:B10,1,D2:D10,1).Sample data
Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Task | Team | Priority | Due | Hours |
| 2 | Update price list | Sales | High | Nov 12, 2026 | 3 |
| 3 | Renew SSL certificate | IT | High | Nov 9, 2026 | 1 |
| 4 | Q4 forecast | Finance | Medium | Nov 20, 2026 | 6 |
| 5 | Laptop refresh | IT | Low | Dec 4, 2026 | 8 |
| 6 | Client QBR deck | Sales | Medium | Nov 9, 2026 | 4 |
| 7 | Close October books | Finance | High | Nov 6, 2026 | 10 |
| 8 | Backup test | IT | Medium | Nov 9, 2026 | 2 |
| 9 | Lead list cleanup | Sales | Low | Nov 27, 2026 | 5 |
| 10 | Expense audit | Finance | Low | Nov 20, 2026 | 3 |
Download this sheet as an Excel practice file (.xlsx)
The Sort dialog: one level per column
The task list should read team by team, with each team's tasks in due-date order. That is two sort keys: Team first, then Due. The A to Z and Z to A buttons only sort by one column, so you need the full Sort dialog, which lets you stack up to 64 levels.
Order matters. The top level is the main grouping; each level below only breaks ties left by the levels above. After this sort Finance comes first, starting with Close October books (6 Nov), then IT, then Sales. Swap the two levels and you get a list in date order where the teams are mixed together, which answers a different question.
- Click any single cell inside the data. Do not select one column, or Excel will ask whether to expand the selection.
- Go to Data > Sort.
- Check that My data has headers is ticked, so row 1 stays on top.
- Under Sort by choose Team, Sort On Cell Values, Order A to Z.
- Click Add Level. Under Then by choose Due, Order Oldest to Newest.
- Click OK.
Why sorting one column is not enough
Sorting by Team alone groups the rows but says nothing about the order inside each group. The formula below is the formula version of clicking Sort A to Z on the Team column. Each team is together, but here within Finance the Q4 forecast (due 20 Nov) sits above Close October books (due 6 Nov).
People often try to fix this by sorting Team, then sorting Due. The second sort reorders the whole list by date and breaks up the teams again. Use levels in one sort instead.
Result: spills 9 rows × 5 columns
| Q4 forecast | Finance | Medium | 46346 | 6 |
| Close October books | Finance | High | 46332 | 10 |
| Expense audit | Finance | Low | 46346 | 3 |
| Renew SSL certificate | IT | High | 46335 | 1 |
| Laptop refresh | IT | Low | 46360 | 8 |
| Backup test | IT | Medium | 46335 | 2 |
| Update price list | Sales | High | 46338 | 3 |
| Client QBR deck | Sales | Medium | 46335 | 4 |
| Lead list cleanup | Sales | Low | 46353 | 5 |
The teams are grouped (Finance, IT, Sales), but the due dates inside each team are not in order: Q4 forecast on 20 Nov is listed before Close October books on 6 Nov.
Add a third level to break ties
Two levels are not always enough. IT has two tasks due on 9 Nov, and Finance has two due on 20 Nov. With only Team and Due as keys, Excel has no rule for which of each pair comes first, so the order of those rows is not something you chose.
Count the ties before you decide how many levels you need. This COUNTIFS checks how many rows share row 3's team and due date. Fill it down: any result above 1 is a tie. Across the whole list, =SUMPRODUCT(--(COUNTIFS(B2:B10,B2:B10,D2:D10,D2:D10)>1)) returns 4, meaning four rows are in a tie. Add a third level, such as Priority or Hours, to settle them.
Result: 2
2: Renew SSL certificate shares IT and 9 Nov with Backup test, so a third sort level is needed to fix their order.
Sort High, Medium, Low in that order
Sorting Priority A to Z gives High, Low, Medium, because it is alphabetical. For an order that is not alphabetical, use a custom list in the Order box. Excel remembers the list, so you only create it once per computer.
If you would rather not create a custom list, add a helper column with a rank number and sort by that column instead. MATCH finds each priority's position in a fixed list, so High is 1, Medium 2 and Low 3. Fill it down, sort by it smallest to largest, and the helper works in every Excel version and survives being emailed to someone else.
- In the Sort dialog, add a level for Priority.
- In its Order box choose Custom List.
- Under List entries type High, Medium, Low, each on its own line, then click Add and OK.
- Move the Priority level to where it belongs with the up and down arrows, then click OK.
Result: 1
1, because Update price list is High, the first item in the list. Medium rows get 2 and Low rows get 3.
A formula that stays sorted: SORTBY and SORT (Excel 365 / 2021)
The Sort dialog rearranges the data once. If new tasks keep arriving and you want a view that re-sorts itself, use a formula on another sheet or to the right of the data. =SORTBY(A2:E10,B2:B10,1,D2:D10,1) sorts the rows by Team A to Z, then by Due oldest first. Each extra key is another pair of range and order, where 1 is ascending and -1 descending.
SORT does the same with arrays: =SORT(A2:E10,{2,4},{1,1}) sorts by the 2nd column, then the 4th. SORTBY is usually easier to read and can sort by a column you do not return, and it handles a custom order too: =SORTBY(A2:E10,B2:B10,1,MATCH(C2:C10,{"High","Medium","Low"},0),1,D2:D10,1) sorts by team, then priority, then due date. These array forms are valid in Excel 365 and 2021, but the Cellwise practice engine cannot run them, so try them in Excel. In Excel 2019 and earlier, neither function exists; use the Sort dialog.
Keep the header row out of the sort
If you include row 1 in a SORT formula, or untick My data has headers in the dialog, the header is sorted like any other row. Here "Team" sorts after "Sales", so the header row lands at the bottom of the result.
In a formula, start the range at row 2 and type the headers above it. In the dialog, keep My data has headers ticked; Excel guesses this setting from your data, so check it every time, especially when the header and the data are both text.
Result: spills 10 rows × 5 columns
| Q4 forecast | Finance | Medium | 46346 | 6 |
| Close October books | Finance | High | 46332 | 10 |
| Expense audit | Finance | Low | 46346 | 3 |
| Renew SSL certificate | IT | High | 46335 | 1 |
| Laptop refresh | IT | Low | 46360 | 8 |
| Backup test | IT | Medium | 46335 | 2 |
| Update price list | Sales | High | 46338 | 3 |
| Client QBR deck | Sales | Medium | 46335 | 4 |
| Lead list cleanup | Sales | Low | 46353 | 5 |
| Task | Team | Priority | Due | Hours |
The header row Task, Team, Priority, Due, Hours ends up as the last row of the result, because "Team" sorts after "Sales".
Common mistakes
Selecting one column and choosing Continue with the current selection
Only that column moves, so every task now sits next to the wrong team and date. Press Ctrl+Z straight away. Next time click a single cell, or choose Expand the selection.
A blank row or column in the middle of the data
Excel treats the blank as the edge of the data and only sorts part of it. Delete the blank row or column, or select the whole range before Data > Sort.
Dates or numbers stored as text
Text sorts separately from real dates and numbers, so the order looks random. Excel may show a Sort Warning about numbers stored as text. Convert the column to real values first.
Merged cells in the range
Excel refuses with a message that merged cells need to be the same size. Unmerge them (Home > Merge & Center) and use Center Across Selection for the look instead.
FAQ
How do I sort by two columns in Excel?
Go to Data > Sort, set the first column under Sort by, click Add Level, and set the second column under Then by. Excel sorts by the first column and uses the second only where the first one ties.
How many columns can I sort by in Excel?
The Sort dialog accepts up to 64 levels. In practice two or three are enough; add another only when rows still tie on the levels you have.
How do I sort by date and then by name?
Use Data > Sort with Due (Oldest to Newest) as the first level and the name column (A to Z) as the second. If the dates sort in a strange order, they are probably text, not real dates.
Why did sorting mix up my data?
Usually only one column was selected and Excel sorted just that column, or a blank row stopped the sort partway. Undo with Ctrl+Z, click a single cell inside the data and sort again from Data > Sort.
Can I sort columns left to right instead of rows?
Yes. In the Sort dialog click Options and choose Sort left to right, then pick the row to sort by. In a formula, SORT has a by_col argument for the same job.
Functions used
SORTSorts a range, spillsCOUNTIFSCounts with several conditionsSUMPRODUCTMultiply then addMATCHPosition of a value
Related guides
- How to sort data with a formula in Excel
- Excel dates not sorting correctly: how to fix it
- How to convert numbers stored as text in Excel
- How to filter with multiple criteria in Excel
- How to calculate cumulative percentage in Excel
- How to rank numbers in Excel
Updated