Skip to main content

sortByRowNumbers

Sorts a table region by sorting a single row's values in ascending order.

To perform the opposite effect, use sortByRowNumbersReverse 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.

Examples

Assume a "Describe the Table" project with this data:

ID

Branch

Sales

Target

Profit

Row 1

1001

Pittsburgh

478,745.37

500,000

8,756.34

Row 2

1002

Boston

329,493.49

300,000

10,451.41

Row 3

1003

Los Angeles

467,359.45

450,000

12,059.78

Row 4

1004

Chicago

463,603.17

400,000

9,452.35

Note

The first table column — ID in table above — contains the row names.

To get a table region comprising the Sales, Target, and Profit columns for Rows 1001 and 1002 only:

[[rowsInRegion(columns(Sales, Target, Profit), '1001', '1002')]]

The result is this table region:

Sales

Target

Profit

1001

478,745.37

500,000

8,756.34

1002

329,493.49

300,000

10,451.41

To sort this region in ascending order, using the values in Row 1001:

[[

inputRegion = rowsInRegion(columns(Sales, Target, Profit), '1001', '1002')

sortByRowNumbers(inputRegion, '1001')

]]

The result is this sorted table region:

Profit

Sales

Target

1001

8,756.34

478,745.37

500,000

1002

10,451.41

329,493.49

300,000

Note

The column order has changed from SalesTargetProfit to ProfitSalesTarget.

To sort the region in ascending order, using the values in Row 1002:

[[

inputRegion = rowsInRegion(columns(Sales, Target, Profit), '1001', '1002')

sortByRowNumbers(inputRegion, '1002')

]]

This changes the column order from SalesTargetProfit to ProfitTargetSales.

Profit

Target

Sales

1001

8,756.34

500,000

478,745.37

1002

10,451.41

300,000

329,493.49

Note

In a "Describe Row in Context" project, the column variables are SalesColumn, TargetColumn, and ProfitColumn.