AnalystPracticeGuides
DashboardSign up

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.

Watch it solved. Formula 6: top 5 without touching the data (SORT + TAKE), from 6:06, in our video “7 Mind-Blowing Excel Formulas I Wish I'd Learned Sooner”. Pressing play loads the video from YouTube (privacy). Open on YouTube

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

Updated November 2026.

← All free guides