Syntax
| Parameter | Description |
|---|---|
| array | Parameter of the SORTBY function. |
| by_array1 | Parameter of the SORTBY function. |
| [sort_order1] | (Optional.) Parameter of the SORTBY function. |
| ... | Parameter of the SORTBY function. |
Examples
Sort names by scores
=SORTBY(A2:A20, B2:B20, -1)
Multi-level sort
=SORTBY(A2:C50, B2:B50, 1, C2:C50, -1)
Sort products by calculated margin
=SORTBY(A2:D30, (D2:D30-C2:C30)/C2:C30, -1)
Common Errors
The sort-by array has a different number of rows than the main array.
The spill range contains non-empty cells that block the output.
Tips
SORTBY's biggest advantage: you can return columns A:C but sort by column E without including E in the output. SORT can't do this.
The by_array can be a formula, not just a range. Sort by LEN(A2:A20) to sort by text length, or by MONTH(D2:D20) to sort by month.
Add as many by_array/sort_order pairs as needed. Each pair after the first acts as a tiebreaker for the previous sort level.
Try SORTBY in Viztab
Import your data and use SORTBY with 370+ other formulas. No signup required.
Open Viztab