Skip to main content Skip to complementary content

FirstSortedValue - chart function

FirstSortedValue() returns the value from the expression specified in value that corresponds to the result of sorting the sort_weight argument, for example, the name of the product with the lowest unit price. The nth value in the sort order, can be specified in rank. If more than one resulting value shares the same sort_weight for the specified rank, the function returns NULL.

Syntax:  

FirstSortedValue([{SetExpression}] [DISTINCT] [TOTAL [<fld {,fld}>]] value, sort_weight [,rank])

Return data type: dual

Arguments
Argument Description
value Output field. The function finds the value of the expression value that corresponds to the result of sorting sort_weight.
sort_weight Input field. The expression containing the data to be sorted. The first (lowest) value of sort_weight is found, from which the corresponding value of the value expression is determined. If you place a minus sign in front of sort_weight, the function returns the last (highest) sorted value instead.
rank By stating a rank "n" larger than 1, you get the nth sorted value.
SetExpression By default, the aggregation function will aggregate over the set of possible records defined by the selection. An alternative set of records can be defined by a set analysis expression.
DISTINCT If the word DISTINCT occurs before the function arguments, duplicates resulting from the evaluation of the function arguments are disregarded.
TOTAL If the word TOTAL occurs before the function arguments, the calculation is made over all possible values given the current selections, and not just those that pertain to the current dimensional value, that is, it disregards the chart dimensions.

By using TOTAL [<fld {.fld}>], where the TOTAL qualifier is followed by a list of one or more field names as a subset of the chart dimension variables, you create a subset of the total possible values.

Defining the aggregation scope

Example: Chart expressions
Example Result
FirstSortedValue (Product, UnitPrice) Returns the Product with the lowest UnitPrice.
FirstSortedValue (Product, UnitPrice, 2) Returns the Product with the second-lowest UnitPrice.
FirstSortedValue (Customer, -UnitPrice, 2) Returns the Customer with the Product that has second-highest UnitPrice.
FirstSortedValue (Customer, -UnitPrice*UnitSales, 2) Returns the Customer with the second-highest sales order value, UnitPrice multiplied by UnitSales.

Example - FirstSortedValue fundamentals

Example - FirstSortedValue scenario

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!