Excel SORT & SORTBY: Dynamic Data Sorting
SORT Function (Excel) is a Excel function that sortby sorts a2:d100 by two columns: first by column d (revenue) in descending order (-1), then by column a (name) in ascending order (1). Formula Genius generates and validates this formula automatically from a plain-English prompt.
SORT and SORTBY create live-sorted copies of your data. Change the source, the sorted output updates automatically.
The Formula
"Sort a sales table by revenue descending, then by name ascending"
=SORTBY(A2:D100, D2:D100, -1, A2:A100, 1)
SORTBY sorts A2:D100 by two columns: first by column D (revenue) in descending order (-1), then by column A (name) in ascending order (1). Unlike SORT, SORTBY lets you sort by columns that aren't in the output range.
Step-by-Step Breakdown
- SORTBY(array, by_array1, sort_order1, [by_array2, sort_order2]) takes the data and sort criteria
- A2:D100 is the data to sort and return
- D2:D100, -1 sorts by revenue descending first
- A2:A100, 1 then sorts ties by name ascending
- Results spill automatically into adjacent cells
Edge Cases & Warnings
- SORTBY arrays must be the same height as the data array
- Results spill — ensure enough empty space below and to the right
- -1 = descending, 1 = ascending (required, not optional)
- Requires Excel 365 or Excel 2021+
Examples
"Data: Alice $5000, Bob $8000, Carol $5000"
Bob $8000, Alice $5000, Carol $5000
"SORT(A2:D100, 4, -1)"
Sorts by 4th column descending (simpler syntax)
Frequently Asked Questions
What's the difference between SORT and SORTBY?
SORT sorts by a column index number within the array. SORTBY sorts by any external array, even one not in the output. SORTBY is more flexible.
Can I combine SORT with FILTER?
Yes. =SORT(FILTER(data, criteria), column, order) filters first, then sorts the results.
Can't find what you need?
Describe any formula in plain English and Formula Genius will generate, explain, and validate it — instantly.