SUM
Synopsis
SUM(dynarray)
Arguments
dynarray | An expression that resolves to a dynamic array of numeric values. |
Description
The SUM function adds the values the elements in a dynamic array and returns the sum as a dynamic array. If an element is missing or has a null string or a non-numeric value, SUM parses its value as 0 (zero).
-
If all of the elements in dynarray are on the same dynamic array level, SUM returns a dynamic array consisting of a single value, the sum of the elements. This is shown in the following example, in which each SUM returns 34:
a=10:@FM:9:@FM:8:@FM:7 b=10:@VM:9:@VM:8:@VM:7 c=10:@SM:9:@SM:8:@SM:7 PRINT SUM(a); ! returns 34 PRINT SUM(b); ! returns 34 PRINT SUM(c); ! returns 34
-
If elements in dynarray are on different dynamic array levels, SUM returns a dynamic array in which elements at the lowest array level are summed. Values at higher levels are returned as array elements. This is shown in the following example:
a=9:@VM:10:@VM:11:@FM:8:@FM:7 PRINT SUM(a); ! returns 30^8^7 b=9:@VM:10:@VM:11:@SM:8:@SM:7 PRINT SUM(b); ! returns 9^10^26
The SUM function adds dynamic array values that are on the same dynamic array level. To add all values in a dynamic array, regardless of level, use the SUMMATION function. To add the elements of two dynamic arrays, use the ADDS function.