A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Clarification: How to initiate a dialogue to build the SORT
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I want to understand how to sort an array by multiple criteria in Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Clarification: How to initiate a dialogue to build the SORT
To sort an Excel range or table by multiple criteria, use either the built‑in Sort dialog or dynamic array functions like SORT/SORTBY.
You can also start from Home > Sort & Filter > Custom Sort and then add multiple levels in the same way.
Use SORT when the data is already in a single array and only one sort key is needed, or when sort index is sufficient:
=SORT(array, [sort_index], [sort_order], [by_col])
SORT returns a spilled array; Excel automatically sizes the output range.
For multiple criteria in formulas, use SORTBY:
=SORTBY(array, by_array1, [sort_order1], [by_array2], [sort_order2], …)
Example: sort a table in A2:D100 first by Department (A2:A100 ascending), then by Salary (D2:D100 descending):
=SORTBY(A2:D100, A2:A100, 1, D2:D100, -1)
This returns the entire table sorted by multiple criteria. Because SORTBY works on ranges instead of column index numbers, it is more robust if columns are inserted or deleted.
References: