FormulaCamp
Completed
← All functions
Dynamic arrays

SORT

Sorts an array.

Syntax

SORT(array, [sort_index], [sort_order], [by_col])

Example: =SORT(A2:C100,3,-1)

Available in: Excel 2021+, Microsoft 365

SORT returns a sorted copy of a range and spills it into the cells below: =SORT(array, [sort_index], [sort_order], [by_col]). Because the original data is untouched, the sorted list updates whenever the source changes.

When to use it

Arguments explained

Worked examples

Largest to smallest

ABC
1RegionRepAmount
2EastAna1200
3WestBen850
4EastCara430
5NorthDan970
6WestEli1500
7EastAna610

Formula: E2: =SORT(C2:C7,1,-1)

Result: Spills down: 1500, 1200, 970, 850, 610, 430

sort_order -1 means descending.

Sort a whole table by Amount

ABC
1RegionRepAmount
2EastAna1200
3WestBen850
4EastCara430
5NorthDan970
6WestEli1500
7EastAna610

Formula: E2: =SORT(A2:C7,3,-1)

Result: Spills down: West, East, North, West, East, East

The table spills with rows kept together; the first column is shown, ordered by Amount (column 3) descending.

Sorted distinct regions

ABC
1RegionRepAmount
2EastAna1200
3WestBen850
4EastCara430
5NorthDan970
6WestEli1500
7EastAna610

Formula: E2: =SORT(UNIQUE(A2:A7))

Result: Spills down: East, North, West

UNIQUE removes duplicates, then SORT orders the list A to Z.

Try it

A tiny spreadsheet with example data. Edit the formula or any number and see the result.

Formula in F2: =SORT(B2:D7,3,-1)

Example spreadsheet for SORT
ABCDEFGH
1RegionProductUnitsPriceResult
2EastPen1202.5Lamp3025
3WestPen802.5Lamp1525
4EastBook4512Book4512
5NorthBook6012Book6012
6WestLamp3025Pen1202.5
7EastLamp1525Pen802.5
Result in F2: Lamp
Practice this in a lesson: UNIQUE and SORT

Common errors and how to fix them

Related functions

Frequently asked questions

How do I sort by two columns?
Pass arrays: =SORT(A2:C7,{1,3},{1,-1}) sorts by column 1 ascending, then column 3 descending.
What is the difference between SORT and SORTBY?
SORT sorts by a column of the array; SORTBY sorts by any separate range.
Does SORT change my data?
No. It creates a sorted copy.
How do I get the top 3?
Use TAKE(SORT(...),3) in Microsoft 365, or INDEX with a sequence.

More in Dynamic arrays