Ravindra BagaleCourses & study guides Track your progress

Excel SORTBY Function

Chala mitrano — today SORTBY. Sort this block using that column’s keys — even if keys are outside.

Fictional sample data for learning. Sort packs by weight while showing names — Coimbatore mills and Manchester wholesale.

Purpose

Sort a range by the values in another range or array.

Return value

A spilled array sorted by the by_array.

Syntax

SORTBY(array, by_array1, [sort_order1], …)

Arguments

ArgumentRequired?Description
arrayRequiredArray to return sorted.
by_array1RequiredKeys that decide order.
sort_order1Optional1 asc, −1 desc.
…OptionalMore by_array/order pairs.

Version

Microsoft 365 / Excel 2021+ with dynamic arrays. LibreOffice limited; Google Sheets has FILTER/SORT/UNIQUE/SEQUENCE/RANDARRAY cousins.

How to use — Why → What → How

Why: When the sort key is not inside the returned columns, SORTBY shines. Sort packs by weight while showing names — Coimbatore mills and Manchester wholesale. In Indian back offices and foreign sister teams, SORTBY shows up on live dashboards and spill ranges every week.

What: SORTBY orders array according to by_array. Multiple key pairs allowed. Read every argument in the table once before you type; each one changes the answer on purpose.

How — numbered steps:

  1. Type =SORTBY(A2:A20,B2:B20,-1).
  2. Keep by_array same height as array.
  3. Add second keys for tie-breaks.

Ravindra Bagale's Tip

Friends, after SORTBY, find one column or range in a real workbook this week where this lesson saves time.

Ravindra Bagale's Tip

Friends, sleep on SORTBY; rebuild example 1 tomorrow without looking.

Ravindra Bagale's Tip

Friends, say the business question in plain words before =SORTBY.

Ravindra Bagale's Tip

Friends, check a known case with a calculator before you trust a long SORTBY chain.

Ravindra Bagale's Tip

Friends, after you finish SORTBY, open yesterday’s real workbook and find one place this function would have saved ten minutes.

Ravindra Bagale's Tip

Friends, treat SORTBY like a seatbelt on spill ranges — clear #SPILL! blocks first.

Download practice file: practice-sortby.xlsx (includes sheet About this data, practice sheets, and Answers).

Worked examples

1) Names by marks

Coimbatore.

NameMarks
Asha72
Ben90
Cid85
Formula: =SORTBY(A2:A4,B2:B4,-1)

Result: {Ben;Cid;Asha}

What it means: Names ordered by marks.

2) Asc key

Fees.

Item$
Bag40
Cup20
Lid60
Formula: =SORTBY(A2:A4,B2:B4,1)

Result: {Cup;Bag;Lid}

What it means: Cheap first.

3) Manchester £

SKU.

SKU£
A5
B2
C8
Formula: =SORTBY(A2:A4,B2:B4,-1)

Result: {C;A;B}

What it means: High £ first.

4) Two keys

City then tip.

NameCityTip
AmyPune5
BobPune12
CidAustin8
Formula: =SORTBY(A2:A4,B2:B4,1,C2:C4,-1)

Result: {Cid;Bob;Amy}

What it means: Austin then Pune high tip.

5) Full rows

Keep cols.

NameMarks
Asha72
Ben90
Formula: =SORTBY(A2:B3,B2:B3,-1)

Result: {Ben,90;Asha,72}

What it means: Both columns.

6) #VALUE!

Height mismatch.

A
x
y
Formula: =SORTBY(A2:A3,B2:B4)

Result: #VALUE!

What it means: by_array height wrong.

Common errors and fixes

#VALUE! — Height mismatch. Fix: Align.
#SPILL! — Blocked. Fix: Clear.
Orders — 1 asc −1 desc. Fix: Remember.

Notes and tips

  • Revisit the SORTBY errors table after the quiz.
  • Build example 1 from memory on a blank sheet.
  • Check number vs text if a result looks wrong.
  • Teach one tip in Marathi or Hindi this week.
  • Keep currency symbols consistent inside one report column (practice mixes ₹ $ £ €).
  • Drill: sort three names by a marks column from memory.
  • SORTBY vs SORT: keys can live outside the returned spill.
  • Fictional sample data only — names and amounts are for learning.
  • Print the SORTBY revision card for one week of real worksheets.
  • Ask juniors to predict before they press Enter.
  • Track your top mistake with this function monthly.
  • Sort packs by weight while showing names — Coimbatore mills and Manchester wholesale.
  • Interview tip: explain the business question before the formula.
  • Classroom drill: invent three brand-new formulas from your city without the page open.
  • If a result looks wrong, check blanks vs zeros before rewriting.
  • When Excel versions differ, note the LibreOffice / Sheets fallback in a cell comment.
  • Prefer clear ranges over whole-column refs on huge sheets if speed matters.
  • Document units (₹, kg, days) in the header so totals stay honest.
  • Print the revision card for SORTBY for one week of real worksheets.
  • When helping a junior, ask them to predict before Enter.
  • Share one tip with a classmate in Marathi or Hindi.
  • Keep currency symbols consistent inside a single report column.
  • Interview tip: explain the business question before the formula.
  • If a result looks wrong, check spill range blocks (#SPILL!) before rewriting.
  • When Excel versions differ, write a LibreOffice / Sheets fallback under a comment.

In real work

Drill: sort three names by a marks column from memory. Sort packs by weight while showing names — Coimbatore mills and Manchester wholesale. Classroom drill: write three brand-new SORTBY formulas on a blank sheet using names from your own city — if you can invent them without the page open, you own the skill. Then break one formula on purpose and watch the error; recovering from that break is half of interview readiness. Always verify with a known case before trusting a long chain. Keep a personal notebook of the one mistake you make most often with this function; review it monthly.

How it compares

SORTBY vs SORT: keys can live outside the returned spill.

Interview corner

vs SORT?
External keys.
Mismatch?
#VALUE!.
Orders?
1 / −1.

SORT, FILTER, UNIQUE

Practice tasks (10)

  1. Task 1. Names by marks desc.
    SORTBY.
  2. Task 2. Items by $ asc.
    Cheap.
  3. Task 3. SKU by £.
    £.
  4. Task 4. Two keys.
    Tie.
  5. Task 5. Force #VALUE!.
    Bad.
  6. Task 6. Interview.
    Talk.
  7. Task 7. Teach.
    Teach.
  8. Task 8. Full rows.
    Cols.
  9. Task 9. Fill.
    Fill.
  10. Task 10. Document.
    Note.

Quick quiz

Q1. SORTBY uses?
Q2. Height must?
Q3. −1 means?
Q4. vs SORT?
Q5. Mismatch?

Answers: Q1=Separate by_array, Q2=Match, Q3=Desc, Q4=External keys OK, Q5=#VALUE! (check after you try).

Revision card

Standalone card (no tip or photo strip). QR opens this lesson. Download the PNG and revise offline.

Revision card: SORTBY
SORTBY revision card