SORTBY Function Excel

If you just need to sortby function excel and move on, the boxed answer at the top is all you need. The rest of this page is for when you want to understand why it works in Excel, adapt it to a trickier version, or make it robust enough to hand to a colleague. We keep the opening short on purpose — the depth is here when you want it, not in your way when you don’t.

Exact answer

In Excel: use =SORTBY(array, by_array, order) — it sorts one range by the values in ANOTHER, which SORT cannot do. Function availability: SORTBY: Excel 2021+. These are Microsoft's version markers; earlier perpetual releases do not include these functions. Check the actual product and update channel before using the formula. A marker does not establish an identical Web/Mac workflow or Google Sheets support.

On this page8

Syntax

=SORTBY(array, by_array1, [sort_order1], ...)

Arguments

Argumentrequired / optionalDescription
arrayrequiredThe range to return, sorted.
by_array1requiredThe values to sort by. Need not be part of array.
sort_order1optional1 ascending (default), -1 descending.

Related functions

SORTFILTERUNIQUE
▤Annotated stepsExcel
1

Function availability: SORTBY: Excel 2021+. These are Microsoft's version markers; earlier perpetual releases do not include these functions. Check the actual product and update channel before using the formula. A marker does not establish an identical Web/Mac workflow or Google Sheets support.

2

Click a cell with enough empty space below and to the right for the whole result.

3

Type =SORTBY( and select the range you want returned.

4

Add a comma and select the range to sort BY — it can be a different column or a calculation.

5

Add -1 for descending, then further by-and-order pairs for extra sort levels.

Ctrl+CthenCtrl+Shift+V⌘+Cthen⌘+Ctrl+VPaste values · WindowsMac

What this does

SORTBY returns a range ordered by a different range. That is its whole reason to exist alongside SORT: the column you want to sort by need not be part of what you return, and it can be a calculated expression that exists nowhere on the sheet. Sorting names by a score you compute on the fly, or ordering a summary by a hidden priority column, are both one formula. Multiple by_array and order pairs give multi-level sorting. Like every dynamic-array function it spills, so it needs empty cells below and returns #SPILL! otherwise. Most people learn this as a sequence of clicks and forget it by next week; learning it as a pattern instead is what lets you apply it to the next, slightly different version of the problem without starting from scratch. That is the difference this page is trying to make. For “sortby function excel”, the reliable version is a short checking loop, not just the first command that appears to work. Run it on a deliberately small range first, watch how the affected formula change, and only then apply the same setup to the full sheet. When a formula is involved, keep the inputs labelled beside it, reference cells instead of typing values, and apply number formatting only after the result checks out. That is what makes a data step that keeps your analysis trustworthy useful in real work: repeatable, auditable, and not dependent on memory or luck.

A worked example

Names in A2:A50 ordered by scores in B2:B50, highest first, returning only the names: =SORTBY(A2:A50, B2:B50, -1). Sorting by a computed key that appears nowhere on the sheet: =SORTBY(A2:A50, LEN(A2:A50), 1) orders by name length. Two levels — region ascending, then revenue descending: =SORTBY(A2:C50, A2:A50, 1, C2:C50, -1). SORTBY sorts by a key that need not exist as a column, which removes the helper column the Sort button would have required. Check the referenced cells, argument order and result type in your workbook. Start with the worked example before changing an input, then compare the changed result with the calculation you expected. An error value or a result of a different type is a reason to inspect the inputs and arguments.

In Google Sheets

Function availability: SORTBY: Excel 2021+. These are Microsoft's version markers; earlier perpetual releases do not include these functions. Check the actual product and update channel before using the formula. A marker does not establish an identical Web/Mac workflow or Google Sheets support. Nothing on this page is behind a login or a download: the exact answer is at the top, and the detail below it is there for when you need it. That is the whole promise here — the answer first, and just enough context to make it stick. For “sortby function excel”, keep the input cells and the result visible while you check the formula in Excel. Follow the worked example and change one input at a time. The steps explain the workbook calculation; this page does not run a live calculator for that task.

Common mistakes

  • Using SORT when the sort key is not in the returned range — that is exactly what SORTBY is for.
  • by_array of a different length to array, which returns #VALUE!.
  • Placing it where cells below are occupied, which returns #SPILL!.

Frequently asked questions

What is the difference between SORT and SORTBY?

SORT orders by a column index within the range itself. SORTBY orders by a separate range or a calculation, which need not be returned at all.

Can I sort by more than one column?

Yes — add further by_array and sort_order pairs, applied in the order given.

Does it change the source data?

No. It returns a sorted copy and leaves the original untouched, unlike the Sort button.

Which Excel release does this formula require?

Function availability: SORTBY: Excel 2021+. These are Microsoft's version markers; earlier perpetual releases do not include these functions. Check the actual product and update channel before using the formula. A marker does not establish an identical Web/Mac workflow or Google Sheets support.