Above - chart function
Above() evaluates an expression at a row above the current row within 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 row directly above. For charts other than tables, Above() evaluates for the row above the current row in the chart's straight table equivalent.
[ , offset [,count]])
Return data type: dual
||The expression or field containing the data to be measured.
Specifying an offsetn, greater
than 0, moves the evaluation of the expression n rows further up from the current row.
Specifying an offset of 0 will evaluate the expression on the current row.
Specifying a negative offset
number makes the Above function work like the Below
function with the corresponding positive offset
By specifying a third argument count greater than 1, the function will return a range of count values, one for each of count
table rows counting upwards from the original cell.
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
On the first row of a column segment, a NULL value is returned, as
there is no row above it.
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:
The table visualization for Example 1.
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 Above(Sum(Sales)).
The column Above(Sum(Sales)) returns NULL for the Customer row containing Astrida, because there is no row above it. The result for the row Betacab shows the value of Sum(Sales) for Astrida, the result for Canutility shows the value for Sum(Sales) for Betacab, and so on.
For the column labeled Sum(Sales)+Above(Sum(Sales)), the row for Betacab shows the result of the addition of the Sum(Sales) values for the rows Betacab + Astrida (539+587). The result for the row Canutility shows the result of the addition of Sum(Sales) values for Canutility + Betacab (683+539).
The measure labeled Above offset 3 created using the expression Sum(Sales)+Above(Sum(Sales), 3) has the argument offset, set to 3, and has the effect of taking the value in the row three rows above the current row. It adds the Sum(Sales) value for the current Customer to the value for the Customerthree rows above. The values returned for the first three Customer rows are null.
The table also shows more complex measures: one created from Sum(Sales)+Above(Sum(Sales)) and one labeled Higher?, which is created from IF(Sum(Sales)>Above(Sum(Sales)), 'Higher').
Tip: This function can also be used in charts other than tables, for example bar charts.
Tip: For other chart types, convert the chart to the straight table equivalent so you can easily interpret which row the function relates to.
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.
In the following screenshot of table visualization for Example 2, the last-sorted dimension is Month, so the Above function evaluates based on months. There is a series of results for each Product value for each month (Jan to Aug) - a column segment. This is followed by a series for the next column segment: for each Month for the next Product. There will be a column segment for each Customer value for each Product.
The table visualization for Example 2.
In the screenshot of table visualization for Example 3, the last sorted dimension is Product. This is done by moving the dimension Product to position 3 in the Sorting tab in the properties panel. The Above function is evaluated for each Product, and because there are only two products, AA and BB, there is only one non-null result in each series. In row BB for the month Jan, the value for Above(Sum(Sales)), is 46. For row AA, the value is null. The value in each row AA for any month will always be null, as there is no value of Product above AA. The second series is evaluated on AA and BB for the month Feb, for the Customer value, Astrida. When all the months have been evaluated for Astrida, the sequence is repeated for the second CustomerBetacab, and so on.
The table visualization for Example 3.
The Above function can be used as input to the range functions. For example: RangeAvg
In the arguments for the Above() 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 immediately above the
current row in the column segment (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.
Data used in examples:
LOAD *, Dual(MonthText,MonthNumber) as Month INLINE [
Crosstable (MonthText, Sales) LOAD * inline [
] (delimiter is '|');