SORTBY Function in Excel: Sort by Another Column

SORTBY Function in Excel: Sort by Another Column featured illustration

πŸ“Ž This article includes 1 downloadable practice file ↓

⏱ 2 min readUpdated 5 October 2026

Dynamic ArrayLevel: ExpertAvailable in: Excel 365 / 2021+

In this article
  1. Syntax
  2. Examples
  3. Example 1
  4. Example 2
  5. SORTBY in practice
  6. Where you will use it
  7. Worked example
  8. Mistakes people make
  9. Related functions
  10. Continue learning

SORTBY sorts one range by the values in another β€” even by a column you do not display.

Advertisement

Syntax

=SORTBY(array, by_array1, [sort_order1], ...)
Argument What it means
by_array1 The values to sort by (same height).
sort_order1 1 ascending, βˆ’1 descending.

Examples

Example 1

=SORTBY(A2:A50, E2:E50, -1)

Names ordered by sales, highest first.

Example 2

=SORTBY(A2:C50, B2:B50, 1, C2:C50, -1)

By region, then by amount.

SORTBY in practice

Where you will use it

  • Sort names by sales
  • Random order: SORTBY(list,RANDARRAY(n))
  • Multi-level sorts

Worked example

OrderFormulaResult
-1=TEXTJOIN(", ",,SORTBY({"Patel";"Shah";"Rao"},{12000;8000;22000},A2))Rao, Patel, Shah
1=TEXTJOIN(", ",,SORTBY({"Patel";"Shah";"Rao"},{12000;8000;22000},A3))Shah, Patel, Rao
-1=TEXTJOIN(", ",,SORTBY({"Patel";"Shah";"Rao"},{12000;8000;22000},A4))Rao, Patel, Shah

Results calculated in Excel.

Mistakes people make

MistakeWhat to do instead
Arrays of different sizes#VALUE!
TiesAdd a second sort key

SORT Β· FILTER Β· TAKE

πŸ“š Part of the free Excel course: Beginner β†’ Expert Β· Try it in the Formula Lab or ask the AI Helper.

⚑ Interactive Practice Lab & Formula Tester:

Test formulas dynamically in our web formula laboratory or download the companion Excel workbook.

πŸ“Ž Practice files for this article

  • πŸ“—
    Practice workbook: Dynamic arrays18 tasks on realistic sales data β€” type your formula, the Check column turns green when it is right. Answers sheet included.
    ⬇ XLSX Β· 35 KB

Free to use for learning. Files with macros (.bas) are plain text β€” import them with Alt+F11 β†’ File β†’ Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free Β· AI can be wrong

Leave a Reply

Your email address will not be published. Required fields are marked *