Sort data by using SORTBY()
=SORTBY(A2:C6, C2:C6, -1)Spill the reps sorted by sales, largest first. SORTBY takes what to return, then the column to sort by and its order: 1 for ascending, -1 for descending.
What the MO-211 task asks
A SORTBY task in our MO-211 practice exams asks for a list in the order of something else: “in L4, one formula must spill the therapist names I4:I8 ordered by Caseload, largest first”, or “spill the twelve titles ordered by Net, largest first”.
Two details decide the marks. “Largest first” is descending, -1; SORTBY's default is ascending. And the sort column does not have to be returned: sorting names by caseload returns only the names.
“One formula must spill” means our grader checks for a dynamic-array formula and the spilled values. A list sorted with the Sort button, or typed in order, scores nothing.
Worked examples
Type these into a blank sheet to follow along. Every result below is what Excel showed.
| A | B | C | |
|---|---|---|---|
| 1 | Rep | Region | Sales |
| 2 | Ana | East | 420 |
| 3 | Ben | West | 610 |
| 4 | Cara | East | 380 |
| 5 | Dev | North | 515 |
| 6 | Eli | West | 290 |
=SORTBY(A2:A6, C2:C6, -1)Only the names spill, in the order of their sales, largest first.
=SORTBY(A2:A6, C2:C6)Without a sort order, SORTBY sorts ascending: smallest first.
=SORTBY(A2:C6, B2:B6, 1, C2:C6, -1)Region A to Z first, then within each region sales largest first: East has Ana's 420 before Cara's 380.
=SORTBY(A2:C6, C2:C6, -1)All three columns, ordered by Sales. This is what the video below builds, in E2.
Watch it done in Excel
The last example above, recorded in real Excel on the same grid.
Exam traps
=SORTBY(A2:A6, C2:C6) puts Eli first. “Largest first” needs the -1.
=SORTBY(A2:A6, C2:C5, -1) returns #VALUE!: the column you sort by must be as tall as what you return.
=SORTBY(A1:A6, C1:C6, -1) sorts the header in with the data, and Rep comes out at the top only because the text Sales sorts above every number.
Data > Sort reorders the source and leaves no formula. A task that says “one formula must spill” checks for the formula.
FAQ
SORTBY or SORT?
SORT is on MO-210 and sorts by a column of what it returns. SORTBY, on MO-211, sorts by any column, returned or not, and takes several sort keys.
What does 0 do as a sort order?
Nothing useful: =SORTBY(A2:A6, C2:C6, 0) returns #VALUE!. The order is 1 or -1.
Does the spill update when the data changes?
Yes. Change Eli's sales to 700 and he moves to the top of the spill straight away.
New to this function?
This page covers what the exam asks. For the full how-to — every argument, more examples and a practice workbook — read our guide on dfwexcel.com.
The SORTBY function, explained — dfwexcel.comTry it under exam conditions
Take a full, timed MO-211 practice exam, upload the workbook you built, and get a score out of 1000 with a per-task breakdown of where the points went. Your first one is free.
No credit card needed.
