Quick Answer & Formula
Excel
Sheets
Beginner
=SORT(array, [sort_index], [sort_order], [by_col]) SORT orders a dataset by a specific column index: =SORT(A2:D100, 4, -1) sorts by column 4 in descending order. Use SORTBY to sort by a column that is not part of the returned output range.
SORT & SORTBY Functions in Excel & Google Sheets
The SORT and SORTBY functions allow you to generate self-updating, sorted views of your data without manually clicking the Data ribbon or disrupting the original source table.
1. Basic Descending Sort
To sort an Employee table (A2:D20) by Salary (Column 4) in descending order (highest earners first):
=SORT(A2:D20, 4, -1)
2. Multi-Level Sorting with SORTBY
To sort by Department (Col B) Ascending, then by Sales (Col C) Descending:
=SORTBY(A2:D50, B2:B50, 1, C2:C50, -1)
?
Frequently Asked Questions
How do I sort by multiple columns (e.g. Department A-Z, then Salary highest-to-lowest)?
Use SORTBY: =SORTBY(A2:D100, B2:B100, 1, D2:D100, -1).