We’re improving Formula Genius. We’re redesigning the app and fixing issues along the way. Sorry for any disruption, and thank you for your patience.
Excel beginner

Excel SORT & SORTBY: Dynamic Data Sorting

SORT and SORTBY create live-sorted copies of your data. Change the source, the sorted output updates automatically.

Formula Genius can generate a draft from a plain-English prompt. Supported formulas can be checked with sample cases; review the coverage on the result.

The formula

Prompt

"Sort a sales table by revenue descending, then by name ascending"

Excel
=SORTBY(A2:D100, D2:D100, -1, A2:A100, 1)

SORTBY sorts A2:D100 by two columns: first by column D (revenue) in descending order (-1), then by column A (name) in ascending order (1). Unlike SORT, SORTBY lets you sort by columns that aren't in the output range.

Step-by-step breakdown

  1. SORTBY(array, by_array1, sort_order1, [by_array2, sort_order2]) takes the data and sort criteria
  2. A2:D100 is the data to sort and return
  3. D2:D100, -1 sorts by revenue descending first
  4. A2:A100, 1 then sorts ties by name ascending
  5. Results spill automatically into adjacent cells

Edge cases & warnings

  • SORTBY arrays must be the same height as the data array
  • Results spill — ensure enough empty space below and to the right
  • -1 = descending, 1 = ascending (required, not optional)
  • Requires Excel 365 or Excel 2021+

Examples

Prompt

"Data: Alice $5000, Bob $8000, Carol $5000"

Excel
Bob $8000, Alice $5000, Carol $5000
Prompt

"SORT(A2:D100, 4, -1)"

Excel
Sorts by 4th column descending (simpler syntax)

Frequently asked questions

What's the difference between SORT and SORTBY?

SORT sorts by a column index number within the array. SORTBY sorts by any external array, even one not in the output. SORTBY is more flexible.

Can I combine SORT with FILTER?

Yes. =SORT(FILTER(data, criteria), column, order) filters first, then sorts the results.

Can't find what you need?

Describe a formula in plain English. Formula Genius drafts and explains it, and can check supported formulas on sample cases.