SORTBY Function in Microsoft Excel: Syntax, Examples & Compatibility
Learn how to sort one data range using a separate numeric or text key in Microsoft Excel. Includes syntax, two verified-by-reasoning results, troubleshooting and portability notes.
Verification status: See the evidence and test scope described in this guide. How formula examples are checked
Quick answer: sort one data range using a separate numeric or text key in Microsoft Excel. The reproducible examples below use explicit values so the formula’s meaning is testable without a large workbook.
Evidence: The function name and syntax are documented in the linked vendor function reference. Expected outputs were independently reasoned or checked outside the application. These are not native Microsoft Excel test results. A guide being published here does not certify every software release or file-import scenario.
Availability and version history
- Introduced: Documented by Excel 2021; the original Microsoft 365 rollout date is not established. Version marker.
- Availability: Official help lists Excel for Microsoft 365, Excel for Microsoft 365 for Mac, Excel 2024, Excel 2024 for Mac, Excel 2021, Excel 2021 for Mac, Excel for iPad, Excel for iPhone, Excel for Android tablets, Excel for Android phones.
- Checked: October 14, 2026; official SORTBY reference. Documentation check, not a new native test; existing example-verification notes retain their scope.
Syntax and arguments
=SORTBY(array, by_array1, [sort_order1], [by_array2, sort_order2], ...)
array is the output dataset; required by_array1 supplies aligned sort keys. An omitted sort_order defaults to 1 (ascending); use -1 for descending. Further key arrays and their order arguments are optional. A key array must be one row high or one column wide and align with the corresponding source dimension.
Best use case: Sort one data range using a separate numeric or text key.
Set up the example sheet
Enter the following sales results:
| Row | A: Agent | B: Units |
|---|---|---|
| 2 | Ana | 3 |
| 3 | Bo | 8 |
| 4 | Cy | 5 |
Enter the formula in an unused cell. For a formula returning several values, leave an unobstructed area where those values can expand. These formulas use comma argument separators in a typical English-language locale; commas or semicolons inside quoted text are data, not argument separators. Adapt the separator if your regional settings require it.
Worked example 1: SORTBY with known input
=SORTBY(A2:B4,B2:B4,-1)
Expected output: rows Bo,8 / Cy,5 / Ana,3.
The separate key column B controls descending numeric order while both data columns stay aligned.
Worked example 2: a second SORTBY case
=SORTBY(A2:A4,B2:B4,1)
Expected output: vertical list Ana, Cy, Bo.
The displayed names follow units from smallest to largest: 3, 5, then 8.
Compare both results before replacing literal values or short sample ranges with your own workbook data. For a spilling formula, compare every output cell, not only the top-left result.
A second key resolves a specified tie
Put these four records in G2:I5, with columns Name, Group and Score: Ada,1,80; Bo,2,95; Cy,1,90; Dee,2,85. Group and Score are numbers.
=SORTBY(G2:I5,H2:H5,1,I2:I5,-1)
The complete expected rows are Cy,1,90 / Ada,1,80 / Bo,2,95 / Dee,2,85. Group sorts ascending; within each group, Score sorts descending. The second key is considered when the first key ties. Without that second key, the source does not establish a universal stable tie order, so this guide does not certify one.
The original ascending-name formula also has the same expected result when its final order 1 is omitted. A supplied order other than 1 or -1 has the documented #VALUE! outcome. Keep each key aligned with its original row; independently sorting the keys would change the association.
Practical advice and troubleshooting
When this formula helps: Use SORTBY when you want a sort key independent of the columns you display. Excel SORT instead uses a column index within the source array.
Important edge case: The sort-key range must have an appropriate size. A blocked spill area prevents output; an unstable/ambiguous sort should use an additional tie-breaker key.
If the result differs, first verify the text-versus-number types of the input cells, the argument separators for your locale, and the range size. For dynamic arrays, inspect occupied cells in the output area. An error that looks like a missing function may reflect a software version rather than incorrect data.
Compatibility and version considerations
Google Sheets SORT takes a different signature: SORT(range, sort_column, is_ascending, ...). SORTBY syntax cannot simply be pasted into Google Sheets.
Microsoft documents SORTBY for Excel 2021/2024 and Microsoft 365.
Function availability and parameter behavior must be judged for the specific application and release; a function documented in one spreadsheet does not automatically work in another.
Related guides and official documentation
-
Microsoft Excel documentation for SORTBY — function syntax and current vendor information.
Editorial verification: Vendor catalogue referenced as of 2026-10-12. The two example outputs are independently reasoned; no native application run, screenshot, or version-specific output is claimed. Review the editorial testing standards if you require stronger proof before importing a workbook.