Top - chart function
Top() evaluates an expression at the first (top) row of a column segment in a table. The row for which it is calculated depends on the value of offset, if present, the default being the top row. For charts other than tables, theTop() evaluation is made on the first row of the current column in the chart's straight table equivalent.
Top([TOTAL] expr [ , offset [,count
Return data type: dual
||The expression or field containing the data to be measured.
Specifying an offsetof n, greater than 1, moves the evaluation of the expression
down n rows below the top row.
Specifying a negative offset number makes the Top
function work like the Bottom function
with the corresponding positive offset number.
||By specifying a third parameter count
greater than 1, the function will return a range of count values, one for each of the last count rows of the current column segment. In this form, the
function can be used as an argument to any of the special range
functions. Range functions
If the table is one-dimensional or if the qualifier TOTAL is used as argument, the current column segment is always equal to the
Defining the aggregation scope
Note: A column segment is defined as a consecutive subset of cells having the same values for the dimensions in the current sort order. Inter-record chart functions are computed in the column segment excluding the right-most dimension in the equivalent straight table chart. If there is only one dimension in the chart, or if the TOTAL qualifier is specified, the expression evaluates across full table.
Note: If the table or table equivalent has multiple vertical dimensions, the
current column segment will include only rows with the same values as
the current row in all dimension columns, except for the column showing the last dimension in the inter-field sort order.
Recursive calls will return NULL.
Examples and results:
In the screenshot of the table shown in this example, the table visualization is created from the dimension Customer and the measures: Sum(Sales) and Top(Sum(Sales)).
The column Top(Sum(Sales)) returns 587 for all rows because this is the value of the top row: Astrida.
The table also shows more complex measures: one created from Sum(Sales)+Top(Sum(Sales)) and one labeled Top offset 3, which is created using the expression Sum(Sales)+Top(Sum(Sales), 3) and has the argument offset set to 3. It adds the Sum(Sales) value for the current row to the value from the third row from the top row, that is, the current row plus the value for Canutility.
In the screenshots of tables shown in this example, more dimensions have been added to the visualizations: Month and Product. For charts with more than one dimension, the results of expressions containing the Above, Below, Top, and Bottom functions depend on the order in which the column dimensions are sorted by Qlik Sense. Qlik Sense evaluates the functions based on the column segments that result from the dimension that is sorted last. The column sort order is controlled in the properties panel under Sorting and is not necessarily the order in which the columns appear in a table.
First table for Example 2. The value of Top for the First value measure based on Month (Jan).
Second table for Example 2. The value of Top for the First value measure based on Product (AA for Astrida).
Please refer to Example: 2 in the Above function for further details.
The Top function can be used as input to the range functions. For example: RangeAvg
In the arguments for the Top() function, offset is set to 1 and count is set to 3. The function finds the results of
the expressionSum(Sales) on the three rows starting with the row below the bottom row in the column segment (because the offset=1), and the two rows below that (where there is a row). These three values are used as input to the RangeAvg() function, which finds the average of the values in the supplied range of numbers.
A table with Customer as dimension gives the following results for the RangeAvg() expression.
LOAD *, Dual(MonthText,MonthNumber) as Month INLINE [
Crosstable (MonthText, Sales) LOAD * inline [
] (delimiter is '|');