SORTBY function in Excel
Sorts the contents of a range or array based on the values in a corresponding range or array
=SORTBY(array, by_array1, [sort_order1], [by_array2, sort_order2], …)SORTBY syntax and parameters
Five arguments, two required.
- arrayarrayRequired
The array or range to sort
- by_array1arrayRequired
The array or range to sort on
- sort_order1numberOptional
The order to use for sorting. 1 for ascending, -1 for descending. Default is ascending.
- by_array2arrayOptional
The array or range to sort on
- sort_order2numberRepeating
The order to use for sorting. 1 for ascending, -1 for descending. Default is ascending.
SORTBY examples
Formulas you'll actually reuse.
Deals largest first — the sort key doesn't have to be inside the returned range:
=SORTBY(A2:C200, C2:C200, -1)By region A→Z, then by amount descending within each region:
=SORTBY(A2:C200, B2:B200, 1, C2:C200, -1)
SORTBY in Google Sheets
No direct equivalent — here's the way around.
Try SORTBY in the playground
Edit the example — nothing to install.
Preloaded with the SORTBY formula from Example 1 — change anything and watch it respond.
SORTBY errors
What they mean — and the fixes.
#VALUE!A by_array isn't the same height (or width) as the array being sorted.
Related functions
More ways Excel gets this done.
- ADDRESSReturns a reference as text to a single cell in a worksheetLookupGoogle Sheets
- AREASReturns the number of areas in a referenceLookupNo Google Sheets equivalent
- CHOOSEChooses a value from a list of valuesLookupGoogle Sheets
- CHOOSECOLSReturns the specified columns from an arrayLookupGoogle Sheets
- CHOOSEROWSReturns the specified rows from an arrayLookupGoogle Sheets
- COLUMNReturns the column number of a referenceLookupGoogle Sheets