SORT2
Description
Sorts an existing matrix and returns a new matrix. SORT2 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
SORT2(
matrix
, [ sort_column_1
, ascending_1
], ...) - matrix: The matrix to sort.
- sort_column_1: The column name or position of the value in the top priority sorting column. If you specify asort_column, you must also specify a corresponding ascending boolean.
- 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.
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
=SORT2(A1:B10,"Name",,"Grade",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.
- 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). If you use the column header name (string) the function preserves the column headers, but if you use the column indexes (numbers), the function sorts the headers as data.
- 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
SORT3