Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Can anyone help me in understanding RangeSum function with examples? When should we use it?
Regards,
Dawar
A range-function returned for each not numeric parameter 0 and therefore the function returned always a valid result. For example a calculation of: 1 + 2 + 'A' or 2 + NULL() will be fail and return NULL and the same within a rangesum(1,2,'A') returned 3 respectively rangesum(2, NULL()) returned 2.
Therefore a range-function or quite similar the alt-function is to use where you need to make sure that your calculation returned always a valid result.
- Marcus
hi,
Range functions will replace the following Chart General Numeric Functions: numsum, numavg, numcount, nummin and nummax, which should now be regarded as obsolete.
rangesum(expr1 [ , expr2, ... exprN ])
Returns the sum of a range of 1 to N arguments. As opposed to the + operator, rangesum will treat all non-numeric values as 0.
The argument expressions of this function may contain Chart Inter Record Functions with a third optional parameter, which in themselves return a range of values.
Examples:
rangesum (1,2,4) | returns 7 |
rangesum (1,'xyz') | returns 1 |
rangesum (null( )) | returns 0 |
rangesum (above(count(x),-1,3)) | returns the sum of the three results of the count(x) function evaluated on the row below the current row, the current row and the row above the current row. |
In addition to what Marcus already explained, you can put it very simply like this: what is the difference between Sum() and RangeSum() and '+'. They all seem to add values right?
Note that in a load script, + and RangeSum() can be used "everywhere", but Sum() can only be used in a LOAD statement where some form of aggregation is either active (GROUP BY) or implied.
Best,
Peter