sortByRow
Sorts a table region by the values in one row.
The sort is performed using a comparator function or a lambda expression.
Studio has other sorting functions, some of which take fewer parameters. To perform a single-row sort that uses numeric or string values, consider using these functions instead:
Note
Available in "Describe the Table" and "Describe Row in Context" projects only.
Parameters
INPUT TABLE (table region)
The table region to sort.
SORTING ROW (string)
The row to sort by. Give the row name as a string.
COMPARATOR FUNCTION (function)
A comparator function that defines how to sort the values.
Use a predefined comparator function or lambda expression.
Comparator functions
Name | Description | Equivalent Lambda Expression |
---|---|---|
| Sorts numbers in ascending order. |
|
| Sorts numbers in descending order. |
|
| Sorts strings in alphabetical order. |
|
| Sorts strings in reverse-alphabetical order. |
|
Examples
Assume a "Describe the Table" project with this data:
ID | Branch | State | Manager | Sales | |
---|---|---|---|---|---|
Row 1 | 1001 | Pittsburgh | Pennsylvania | Andrew Gray | 478,745.37 |
Row 2 | 1002 | Boston | Massachusetts | Emma Moore | 329,493.49 |
Row 3 | 1003 | Los Angeles | California | Linda Barclay | 467,359.45 |
Row 4 | 1004 | Chicago | Illinois | Camilla Scott | 463,603.17 |
Note
The first table column — ID in table above — contains the row names.
To get a table region comprising the Branch, State, and Manager columns for Rows 1002 and 1003 only.
[[rowsInRegion(columns(Branch, State, Manager), '1002', '1003')]]
The result is this table region:
Branch | State | Manager | |
---|---|---|---|
1002 | Boston | Massachusetts | Emma Moore |
1003 | Los Angeles | California | Linda Barclay |
To alphabetically sort this region by the values in Row 1002:
[[ inputRegion = rowsInRegion(columns(Branch, State, Manager), '1002', '1003') sortByRow(inputRegion, '1002', stringSort()) ]]
The first line of ATL defines the input table region. The second line alphabetically sorts this region by applying the stringSort()
comparator function to the values in Row 1002.
The result is this sorted table region:
Branch | Manager | State | |
---|---|---|---|
1002 | Boston | Emma Moore | Massachusetts |
1003 | Los Angeles | Linda Barclay | California |
Note
The column order has changed from Branch–State–Manager to Branch–Manager–State.
To alphabetically sort the region by the values in Row 1003:
[[ inputRegion = rowsInRegion(columns(Branch, State, Manager), '1002', '1003') sortByRow(inputRegion, '1003', stringSort()) ]]
This changes the column order from Branch–State–Manager to State–Manager–Branch.
| State | Manager | Branch |
---|---|---|---|
1002 | Massachusetts | Emma Moore | Boston |
1003 | California | Linda Barclay | Los Angeles |
Note
In a "Describe Row in Context" project, the column variables would be BranchColumn
, StateColumn
, and ManagerColumn
.