sortByColumnNumbers
Sorts a table region by sorting a single column's values in ascending order.
To achieve the opposite effect, use sortByColumnNumbersReverse 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 COLUMN (string)
The column to sort by. Give the column name as a string.
Note: The column must contain numbers only.
Examples
Assume a "Describe the Table" project with this data:
ID | Branch | Sales | Target | |
---|---|---|---|---|
Row 1 | 1001 | New York | 478,745.37 | 500,000 |
Row 2 | 1002 | Boston | 329,493.49 | 300,000 |
Row 3 | 1003 | Los Angeles | 467,359.45 | 450,000 |
Row 4 | 1004 | Chicago | 463,603.17 | 400,000 |
Note
The first table column — ID in table above — contains the row names.
To sort the table by Sales in ascending order:
[[sortByColumnNumbers(WholeTable,'Sales')]]
The result is this sorted table region:
| Branch | Sales | Target |
---|---|---|---|
1002 | Boston | 329,493.49 | 300,000 |
1004 | Chicago | 463,603.17 | 400,000 |
1003 | Los Angeles | 467,359.45 | 450,000 |
1001 | New York | 478,745.37 | 500,000 |
You can then interrogate the sorted region with functions such as columnsInRegion and top.
[[ sortedByLowestSales = sortByColumnNumbers(WholeTable,'Sales') worstBranch = top(columnsInRegion(sortedByLowestSales,Branch),1) worstSales = top(columnsInRegion(sortedByLowestSales,Sales),1) worstSalesAbrv = abbreviateNumber(currencyFormat(worstSales)) "The branch with the worst sales is [[worstBranch]], with a total of [[worstSalesAbrv]]." ]]
The printed output is:
The branch with the worst sales is Boston, with a total of $329.5K.
Note
In a "Describe Row in Context" project, the column variables are BranchColumn
and SalesColumn
.