SORT3
Description
Sorts an existing matrix and returns a new matrix. SORT3 assumes that the first row is a header, and returns the header as the first row in the results. SORT3 accepts pairs of parameters, specifying the column to sort by and the sort direction for that column. When ties occur during the sort, arguments for columns after the first column you specified are used.
Syntax
SORT3(
matrix
, [ sort_column_1
, ascending_1
], ...) - matrix: The matrix to sort. SORT3 assumes that the first row is a header, and returns the header as the first row in the results.
- sort_column_1: The column name or position of the value in the top priority sorting column.
- ascending_1: If TRUE, the function sorts the values in the associated column in ascending order; if FALSE, the function sorts the values in the associated column in descending order.
- sort_column_2: The column name or position of the value in the 2nd priority sorting column.
- ascending_2: If TRUE, the function sorts the values in the associated column in ascending order; if FALSE, the function sorts the values in the associated column in descending order.
- sort_column_3: The column name or position of the value in the 3rd priority sorting column.
- ascending_3: If TRUE, the function sorts the values in the associated column in ascending order; if FALSE, the function sorts the values in the associated column in descending order.
Example
This is the original spreadsheet:
A | B | |
|---|---|---|
1 | Name | Grade |
2 | Joe | 85 |
3 | Alice | 92 |
4 | Joe | 90 |
5 | Luis | 92 |
6 | Xibin | 85 |
7 | Alice | 79 |
8 | Joe | 82 |
9 | Luis | 95 |
10 | Xibin | 88 |
11 | Alice | 97 |
The result of
=SORT3(A1:B10,1,,2,FALSE)
is: Name | Grade |
Xibin | 88 |
Xibin | 85 |
Luis | 95 |
Luis | 92 |
Joe | 90 |
Joe | 85 |
Joe | 82 |
Alice | 97 |
Alice | 92 |
Alice | 79 |
Notes
- You can specify up to 8 column/direction pairs. The function ignores empty sort columns.
- Empty parameter pairs are ignored. For strict parameter pairs you can use SORT2.
- To sort all the columns you specified in only one direction, you can use SORT().
- This function sorts the rows in the sourcematrixand returns a new matrix reflecting the sorted rows. The order of the rows is determined by the value insort_column_nand the direction you specified (ascending or descending).
- Specify sort columns either by name (as text strings without any surrounding square brackets) or by position (where the first column is in position 1). You can mix these values (specifying some by name and others by position). With either method, the function preserves the header and returns it as the first row of results.
- When you specify more than one sort column, the function breaks ties by sorting the values in each subsequently specified column. Example: If the first column has three values of the string"hello", and you specified a second column, the function sorts the values in that column for the three rows that have"hello"in the first column. This determines the final order of those three columns.
- This function is intended for use in array formulas.
Related Functions
ARRAYAREA
SORT
SORT2