Dynamic Arrays Last updated: 2026-08-20

SORT & SORTBY Functions in Excel & Google Sheets (Dynamic Array Sorting)

Sort tables and ranges dynamically by single or multiple columns in ascending or descending order using the SORT and SORTBY formulas.

Quick Answer & Formula
Excel Sheets Beginner
=SORT(array, [sort_index], [sort_order], [by_col])

SORT orders a dataset by a specific column index: =SORT(A2:D100, 4, -1) sorts by column 4 in descending order. Use SORTBY to sort by a column that is not part of the returned output range.

SORT & SORTBY Functions in Excel & Google Sheets

The SORT and SORTBY functions allow you to generate self-updating, sorted views of your data without manually clicking the Data ribbon or disrupting the original source table.


1. Basic Descending Sort

To sort an Employee table (A2:D20) by Salary (Column 4) in descending order (highest earners first):

=SORT(A2:D20, 4, -1)

2. Multi-Level Sorting with SORTBY

To sort by Department (Col B) Ascending, then by Sales (Col C) Descending:

=SORTBY(A2:D50, B2:B50, 1, C2:C50, -1)
?

Frequently Asked Questions

How do I sort by multiple columns (e.g. Department A-Z, then Salary highest-to-lowest)?

Use SORTBY: =SORTBY(A2:D100, B2:B100, 1, D2:D100, -1).