The VECTOR SORT ORDER function returns a new vector that specifies the order of the elements in vec. If direction is greater than 0 the entries are sorted from smallest to biggest, otherwise from biggest to smallest. The returned vector contains the zero based index number for the elements in sorted order (that is 0 is the first element, 1 the second and so on). Normally this is used in conjunction with VECTOR REORDER but it can also be used with VECTOR ELM MAP to find min, max and median values.
company : (company1-company5)->scompany
scompany : (sort1-sort5)-> company
so[scompany]=VECTOR SORT ORDER(revenue[company],1)
minrev = VECTOR ELM MAP(revenue[company1],so[sort1])
maxrev = VECTOR ELM MAP(revenue[company1],so[sort5])
medrev = VECTOR ELM MAP(revenue[company1],so[sort3])
sorted rev[scompany] = VECTOR REORDER(revenue[company],so[scompany])
Note that it is not really necessary to define scompany in this example. However, the order of values in sorted rev is no longer by company so it prevents possible confusion to use a different subscript range.
Units: VECTOR SORT ORDER(units,dmnl) --> dmnl
Restrictions: Must appear first on the right and can’t be followed by anything else. Sorting is done on the complete vector relative to the last subscript. Subranges will not work.
Availability: Professional and DSS only.
Sample model: VECTOR RANK + REORDER + SORT ORDER.mdl in FunctionExamples