CUMULATIVESUM function

Synopsis
This function returns an array that is the cumulative sum of all elements previous to its position in the source array.
Variations
CUMULATIVESUM(SourceArray)
Returns the cumulative sum at each position in the source array.
Parameters
SourceArray

Specifies the array from which to retrieve the cumulative sum.

Supported types: Numeric array; Boolean array.
Returns
Returned types: Numeric array.
Examples
1.

The following example returns the cumulative sum of all elements up to each position in the array. The function returns [1, 2, 3, 4, 5].

CUMULATIVESUM([1, 1, 1, 1, 1])
CUMULATIVESUM(SourceArray, StartIndex, Count)
Returns the cumulative sum for only a subset of the array, not considering the elements before the start index as part of the cumulative sum.
Parameters
SourceArray

Specifies the array from which to retrieve the cumulative sum.

Supported types: Numeric array; Boolean array.
StartIndex

Specifies the index of the first element of the subset in the source array.

Supported types: Numeric.
Count

Specifies the number of elements (beginning at StartIndex) to include in the subset of the source array.

Supported types: Numeric.
Returns
Returned types: Numeric array.
Examples
1.

The following example returns the cumulative sums of all elements from the 8th to the 10th indices. The function returns [1, 2, 3].

CUMULATIVESUM([100, 1, 1, 1, 1, 1, 1, 1, 1, 1], 8, 3)
CUMULATIVESUM(SourceArray, Expression)
Returns the cumulative sum at each position in the source array after performing an expression on each element.
Parameters
SourceArray

Specifies the array from which to retrieve the cumulative sum.

Supported types: Numeric array; Boolean array; String array; Point array; Object array.
Expression

Specifies the expression to apply to each element of the source array.

Supported types: Numeric.
Returns
Returned types: Numeric array.
Examples
1.

The following example calculates the cumulative sum of all elements up to each position in the array after evaluating the expression on each element. The function returns [1, 2, 3, 4, 5].

CUMULATIVESUM([10, 10, 10, 10, 10], Item/10)
CUMULATIVESUM(SourceArray, StartIndex, Count, Expression)
Returns the cumulative sum for only a subset of the array after performing an expression on each element, not considering the elements before the start index as part of the cumulative sum.
Parameters
SourceArray

Specifies the array from which to retrieve the cumulative sum.

Supported types: Numeric array; Boolean array; String array; Point array; Object array.
StartIndex

Specifies the index of the first element of the subset in the source array.

Supported types: Numeric.
Count

Specifies the number of elements (beginning at StartIndex) to include in the subset of the source array.

Supported types: Numeric.
Expression

Specifies the expression to apply to each element of the source array.

Supported types: Numeric.
Returns
Returned types: Numeric array.
Examples
1.

The following example calculates evaluates the expression on the subset of the source array indicated by the index and count; this results in array [2, 2]. The function then calculates each elements' cumulative sum, and returns [2, 4].

CUMULATIVESUM([1, 1, 1, 1, 1], 3, 2, Item*2)