To sort a table by more than one column with a live formula — region A–Z, then sales high–low within each region — use SORTBY. It returns a spilled, self-updating sorted copy without touching your source data.
1 = ascending, -1 = descending) in priority order.
The example
Sorted by Region (A–Z), then Sales (high–low) within each region.
| A | B | |
|---|---|---|
| 1 | Region | Sales |
| 2 | East | $170 |
| 3 | East | $90 |
| 4 | West | $200 |
| 5 | West | $120 |
The formula
Region ascending, then Sales descending:
How it works
SORTBY sorts one array by one or more other arrays:
- The first argument is the data to return (
A2:B5). - Then come key/direction pairs:
A2:A5, 1sorts by region ascending first. - The next pair,
B2:B5, -1, breaks ties by sales descending — so within East and within West, the biggest sale is on top. - The result spills as a sorted copy; the original data is untouched and the sort updates live.
SORT vs SORTBY. SORT sorts by column position within the data; SORTBY sorts by separate key arrays (which can even be columns not shown in the output). SORTBY is the flexible one for multi-key sorts.
Try it: interactive demo
Choose the secondary sort direction for Sales within each region.
Variations
SORT by column position
Sort the whole table by its 3rd column descending:
Sort by a custom order
Sort by a helper key that encodes your order (e.g. MATCH against a priority list).
Filter then sort
Combine with FILTER:
Pitfalls & errors
Key arrays must match the data height. Each sort key range needs the same number of rows as the data, or SORTBY returns #VALUE!.
SORTBY needs Excel 365/2021. Older versions show #NAME? — use the Data → Sort dialog (with multiple levels) there.
It returns a copy. The spilled result is separate from the source; edits to the source reflow it, but you can’t edit the sorted spill directly.
Practice workbook
Frequently asked questions
How do I sort by multiple columns with a formula in Excel?
What's the difference between SORT and SORTBY?
How do I filter and sort at the same time?
Stop fighting formulas. Learn them in a day.
This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.
See the Formulas & Functions Class