Sorts range or array by column
=SORTBY(array, by_array, [sort_order], [array/order], ...)
| Parameter | Description |
|---|---|
array |
Range or array to sort. |
by_array |
Range or array to sort by. |
sort_order |
[optional] Sort order. 1 = ascending (default), -1 = descending. |
array/order |
[optional] Additional array and sort order pairs. |
To sort by values in another range:
=SORTBY(B5:B16,C5:C16) // sort B by C values, ascending
=SORTBY(B5:B16,C5:C16,-1) // sort B by C values, descending
To sort by a calculated value:
=SORTBY(B5:B16,LEN(B5:B16)) // sort by text length
=SORTBY(B5:B16,RANDARRAY(12)) // random sort
To sort by multiple levels:
=SORTBY(B5:D14,D5:D14,1,C5:C14,-1) // by D ascending, then C descending
One of the key advantages of SORTBY is the ability to sort data using values that don't appear in the output. In the worksheet below, the goal is to s
=SORTBY(B5:B16,C5:C16,-1)
The array argument is B5:B16 (names only), while by_array1 is C5:C16 (scores). Because only the names are provided for array, the scores are used for
=SORTBY(B5:C16,C5:C16,-1) // returns both names and scores
Unlike the SORT function, SORTBY does not have an argument that controls sorting by rows versus columns. Instead, SORTBY auto-detects the sort orienta
=SORTBY(B4:K5,B5:K5,-1)