SORT and SORTBY: sorting with formulas in Excel
SORT returns a sorted copy of a range that updates when the data changes. SORTBY sorts by columns that don't have to be part of the result. Both are in Microsoft 365 and Excel 2021 or later.
How do you sort by one column?
Names and sales in A2:B20, highest sales first:
=SORT(A2:B20,2,-1)
The 2 is the column inside the range, and -1 means descending.
How do you sort by two columns?
Region ascending, then sales descending:
=SORTBY(A2:C20,B2:B20,1,C2:C20,-1)
How do you build a top 5 list?
Combine SORT with TAKE in Microsoft 365:
=TAKE(SORT(A2:B20,2,-1),5)
or sort only the filtered rows:
=SORT(FILTER(A2:B20,C2:C20="North"),2,-1)
Why not just use the Sort button?
The button changes the order of the original data, once. The formula leaves the data as it is and always stays up to date, which is what a report needs.
Try it yourself. Practise this in a real spreadsheet in your browser, with instant feedback.
Practise SORT
Practise SORT
Updated November 2026.