Mastering the SORT Function in Google Sheets
Sorting data is a fundamental part of data analysis, but clicking the "Sort" button in the menu isn't always enough. When you need your data to sort dynamically, automatically update as new rows are added, or reference complex custom sorting orders, the =SORT() function becomes an essential tool.
Why Use a Formula Instead of the Sort Menu?
Dynamic Updates: Menu sorts are static one-time actions. If new data is added at the bottom of your sheet, you must manually sort again. The
SORT()function creates a dynamic array that instantly re-arranges itself whenever source data changes.Original Data Preservation: The formula outputs sorted data in a new location, leaving your original dataset completely untouched. This is crucial for maintaining chronological logs or preserving raw imports.
Dashboard Integration: By hooking up the
sort_columnargument to a drop-down menu cell (e.g.,D1), you can build interactive dashboards where users can choose how they want to view the data without touching the raw sheets.
Understanding the SORT Syntax
=SORT(range, sort_column1, is_ascending1, [sort_column2, is_ascending2, ...])
range: The data you want to sort (e.g.,
A2:D100).sort_column: The numeric index of the column relative to your range (which column to sort by). Note: You CANNOT use column letters here (like A or B). It must be a relative number. For example, if your range is
B2:D100, columnBis1, not2.is_ascending:
TRUEfor A-Z / 1-99.FALSEfor Z-A / 99-1.
Multi-Column Sorting
Often, there are ties in your primary column (e.g., multiple employees in the same "Department"). You can resolve these ties by adding a secondary column:
=SORT(A2:D100, 2, TRUE, 4, FALSE)
This translates to: "Sort the table first by column 2 ascending. If two rows have the same value in column 2, sort them by column 4 descending."
Advanced Tip: Using QUERY as an Alternative
If your sorting needs become overly complex, or if you need to filter and sort at the same time, consider the =QUERY() function:
=QUERY(A2:D100, "SELECT * ORDER BY Col2 ASC, Col4 DESC", 0)
While QUERY is incredibly powerful, it can be slightly slower on massive datasets and its SQL-like syntax has a steeper learning curve compared to the straightforward SORT generator we've built above.