SORTBY function
Sorts the contents of a range or array based on the values in a corresponding range or array.
Lookup and reference · Excel 2021+
Where can you use it?
Reporting and operations teams. Use functions in this group to retrieve a field from an item, employee or order list, select the right record, or move values into another report.
Scenario in the workbook
Order amounts descending. The sort direction is −1.
A worked example from the workbook
| Row | A | B |
|---|---|---|
| 6 | Source value | Output position |
| 7 | 30 | 1 |
| 8 | 10 | 2 |
| 9 | 20 | 3 |
Record 1
=INDEX(SORTBY($A$7:$A$9,$A$7:$A$9,-1),B7,1)Expected result30
See the inputs and instructions for all 3 examplesCopyable formulas
English Excel · en-US
=INDEX(SORTBY($A$7:$A$9,$A$7:$A$9,-1),B7,1)Turkish Excel · tr-TR
=İNDİS(SIRALAÖLÇÜT($A$7:$A$9;$A$7:$A$9;-1);B7;1)Worked examples
Order amounts descending. The sort direction is −1.
Open the English sheet. Inputs begin at A6. F7:F9 show the live results and G7:G9 show the original results for comparison.
| Row | A | B |
|---|---|---|
| 6 | Source value | Output position |
| 7 | 30 | 1 |
| 8 | 10 | 2 |
| 9 | 20 | 3 |
| Case | Formula | Expected result |
|---|---|---|
| Record 1 | =INDEX(SORTBY($A$7:$A$9,$A$7:$A$9,-1),B7,1) |
30 |
| Record 2 | =INDEX(SORTBY($A$7:$A$9,$A$7:$A$9,-1),B8,1) |
20 |
| Record 3 | =INDEX(SORTBY($A$7:$A$9,$A$7:$A$9,-1),B9,1) |
10 |