MoneyWorks Manual
Sort (tabDelimTable, sortColumn1, [sortType], [descending], [skipfirst])
Result Type: A tab/newline delimited table such as is returned from Analyse()
Definition: Sorts a tab/newline delimited table. sortColumn is the column number to sort by, where 1 = leftmost column, and a negative value counts from the right (i.e -1 = rightmost column). If descending is 0, the table is sorted in ascending order, otherwise it is sorted in descending. For an alphabetic sort, set sortType to SortCaseSensitive
or SortCaseInsensitive
; to treat the column as numeric, set sortType to SortNumeric
. If skipfirst is true, the first row of the table is not sorted (i.e. first row stays at the top of the table—use when the table has headings).
As a special case, if the first parameter is a table type (from CreateTable), the Sort function will convert it to tabular text, sort it, and then convert the result back to a table type.
Note: In MoneyWorks versions prior to 9.2, the sortType parameter was a boolean with true (1) indicating numeric and 0 indicating case insensitive alphabetic. Case insensitivity applies only to the ASCII codepoint range.
Examples: If MyTable is “A\t1\t2\nB\t3\t4\n\C\t5\t6”, as shown below:
A | 1 | 2 |
B | 3 | 4 |
C | 5 | 6 |
Sort(MyTable, 2, 1, 1)
returns
C | 5 | 6 |
B | 3 | 4 |
A | 1 | 2 |
Sort(MyTable, 2, 1, 1, 1)
returns
A | 1 | 2 |
C | 5 | 6 |
B | 3 | 4 |
i.e. first row was heading.
See Also:
CreateTable: Create an empty accumulator table
TableAccumulate: Accumulate numeric column data for a key
TableAccumulateColumn: Accumulate data in one column for a key
TableFind: Look up a key in the table
TableGet: Extract data for a key or index found with TableFind
Transpose: Transpose a tabular delimited string