WRank - script function
WRank() evaluates the rows of a table in the load script, and for each row, displays the relative position of the value of the field evaluated in the load script. When evaluating the table, the function compares the result with the result of the other rows containing the current partition and returns the ranking of the current row within the segment.
WRank can only be used in a Window function. The Window function must include a sorting type and sorting expression. The ranking is applied on the sorting expression.
Syntax:
WRank ([mode[, fmt]])
Return data type: dual
Arguments:
Argument | Description |
---|---|
mode | Optionally, specifies the number representation of the function result. |
fmt | Optionally, specifies the text representation of the function result. |
TOTAL |
If the table is one-dimensional, or if the script is preceded by the TOTAL qualifier, the function is evaluated along the entire column. If the table or table equivalent has multiple vertical dimensions, the current partition 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. |
The ranking is returned as a dual value, which in the case when each row has a unique ranking, is an integer between 1 and the number of rows in the current partition.
In the case where several rows share the same ranking, the text and number representation can be controlled with the mode and fmt parameters.
mode
The first argument, mode, can take the following values:
Value | Description |
---|---|
0 (default) |
If all ranks within the sharing group fall on the low side of the middle value of the entire ranking, all rows get the lowest rank within the sharing group. If all ranks within the sharing group fall on the high side of the middle value of the entire ranking, all rows get the highest rank within the sharing group. If ranks within the sharing group span over the middle value of the entire ranking, all rows get the value corresponding to the average of the top and bottom ranking in the entire partition. |
1 | Lowest rank on all rows. |
2 | Average rank on all rows. |
3 | Highest rank on all rows. |
4 | Lowest rank on first row, then incremented by one for each row. |
fmt
The second argument, fmt, can take the following values:
Value | Description |
---|---|
0 (default) | Low value - high value on all rows (for example 3 - 4). |
1 | Low value on all rows. |
2 | Low value on first row, blank on the following rows. |
The order of rows for mode 4 and fmt 2 is determined by the load order of the table fields.
Example - Adding a ranked field
Example - Adding a ranked field using fmt for a single digit result
Example - Adding a ranked field with multiple partitions
Limitations
WRank has the following limitations:
-
If your fmt value is 0 and you want to use the text part of the dual result for WRank, you must use Text() with Window(WRank). For example: Text(Window(WRank(0), Unit, 'DESC', Age)) as UnitWRankedByAgeText.