Sort

Excel

Select a range of cells > go to the Home tab > Editing > Sort & Filter and then select sorting options.

Tableau

Rank can be added as a table calculation or with the syntax: ~RANK!~(‹field› «, 'direction'») where «direction» can be either asc or desc.

RANK([Country], 'asc')
RANK([Salary], 'desc')

Alteryx

Use the Sort tool (in the Preparation palette).

(and select the Sort and Direction values).

OrgVue

In OrgVue, strings and numbers are sorted differently. Sorting strings: array(‹string_array›).~sort!~('item'«, 'direction'») OR ‹collection›.~sort!~('‹dimension›'«, 'direction'»)

array([2,1,'b','c','a']).sort('item', 'desc'); // returns c,b,a,2,1
// OR
node.d.sort('department', 'asc');

NB.:

  • If no direction is supplied, an ascending order is applied by default.

  • If the values being sorted are of mixed type, sort() lists numbers in ascending order and then sorts strings alphabetically (which can be considered 'ascending order').

Sorting numbers:

It is possible to apply the above syntax when sorting a measure. However, it will treat the measure as if it were a string, e.g. sorting 9.9 -> 800 -> 70 -> ... To correctly sort numerical fields, use: ‹collection›.~sort!~('‹measure›', ~sort.number!~|sort.‹direction›)

node.c.sort('current_salary', sort.number|sort.desc)

tSQL

~ORDER BY!~ ‹field› [‹direction›]

SELECT * 
FROM EmployeeData
ORDER BY CurrentSalary [DESC]

Python

~sorted!~(‹arr›, ‹key=lambda n: n.name›)

sorted(arr, key=lambda n: n.name)

This assumes that the variable arr is an array containing objects. If you want to sort a simple array of strings, you can use: ~sorted!~(‹array›, «reverse=True») where the inclusion of reverse=True reverses the sort order:

sorted(['2','1','b','c','a']) 
# Returns ['1', '2', 'a', 'b', 'c']

sorted(['2','1','b','c','a'], reverse=True) 
# Returns ['c', 'b' , 'a', '2', '1']

NB.:

  • An ascending order is applied by default.

  • If the values being sorted are of mixed type, sorted() lists numbers in ascending order and then sorts strings alphabetically (which can be considered 'ascending order').

  • All numbers must be wrapped in quotes.

Last updated

Was this helpful?