RangeMode - script and chart function
RangeMode() finds the most commonly occurring value (mode value) in the expression or field.
Syntax:
RangeMode(first_expr {, Expression})
Return data type: numeric
Arguments:
The argument of this function may contain inter-record functions which in themselves return a list of values.
- first_expr: The expression or field containing the data to be measured.
- Expression: Optional expressions or fields containing the range of data to be measured.
Limitations:
If more than one value shares the highest frequency, NULL is returned.
Examples:
Example | Result |
---|---|
RangeMode (1,2,9,2,4) |
Returns 2 |
RangeMode ('a',4,'a',4) |
Returns NULL |
RangeMode (null( )) |
Returns NULL |
Example: (using expression)
RangeMode (Above(MyField,0,3))
Returns the most commonly occurring value in the three results of MyField evaluated on the current row and two rows above the current row. By specifying the third argument as 3, the Above() function returns three values, where there are sufficient rows above, which are taken as input to the RangeMode() function.
MyField | RangeMode(Above(MyField,0,3)) |
---|---|
10 | Returns 10 because there are no rows above so the single value is the most commonly occurring. |
2 | - |
8 | - |
18 | - |
5 | - |
9 | - |
Data used in examples:
RangeTab:
LOAD * INLINE [
MyField
10
2
8
18
5
9
] ;
Example: (in table form)
Add the example script to your document and run it. Then add, at least, the fields listed in the results column to a sheet in your document to see the result.
RangeTab3:
LOAD recno() as RangeID, RangeMode(Field1,Field2,Field3) as MyRangeMode INLINE [
Field1, Field2, Field3
10,5,6
2,3,7
8,2,8
18,11,9
5,5,9
9,4,2
];
The resulting table shows the returned values of MyRangeMode for each of the records in the table.
RangeID | MyRangeMode |
---|---|
1 | - |
2 | - |
3 | 8 |
4 | - |
5 | 5 |
6 | - |