Investment Studio > Expressions > Functions > Matrix > MSORT
array msort(array[*][*] table, boolean ascending = TRUE, boolean rowwise = TRUE)
Returns the 2-dimensional table array, sorted rowwise (columnwise) on the first column (row).
If ascending is TRUE, the lowest values are listed first.
If omitted, ascending and rowwise default to TRUE.
Numbers and strings are sorted separately, without any attempt at type conversion. Numbers are always considered lower order than strings: 10000 is lower than "1". Empty elements are always listed last.
Examples
=msort({{2, 1}, {, 5}, {1, 3}, {"-1", 4},})
sorts the argument array rowwise on its first column, returning {{1, 3}, {2, 1}, {"-1", 4}, {, 5}}. Note that "-1" is sorted after 1 and 2 since it's a string (no attempt is made to interpret it as a number).
The row {, 5} ends up last, since its first column is empty. Reverting the sort order doesn't change this:
=msort({{2, 1}, {, 5}, {1, 3}, {"-1", 4},}, FALSE)
returns {{"-1", 4}, {2, 1}, {1, 3}, {, 5}}, i.e. the empty element always ends up last.