Skip to main content
Version: Java (Groovy)

CumSum

CumSum calculates a cumulative sum in an updateBy table operation.

Syntax

CumSum(pairs...)

Parameters

ParameterTypeDescription
pairsString...

The column(s) to be operated on. These can include expressions to rename output columns (e.g., NewCol = Col). If None, the cumulative sum is calculated for all applicable columns in the table.

Returns

An UpdateByOperation to be used in an updateBy table operation.

Examples

The following example performs an updateBy on the source table using the CumSum operation. No grouping columns are given, so the cumulative sum is calculated for all rows in the table.

source = emptyTable(10).update("Letter = (i % 2 == 0) ? `A` : `B`", "X = i")

result = source.updateBy(CumSum("SumX = X"))

The following example builds off the previous by specifying Letter as the grouping column. Thus, the cumulative sum of X is calculated for each unique letter.

source = emptyTable(10).update("Letter = (i % 2 == 0) ? `A` : `B`", "X = i")

result = source.updateBy(CumSum("SumX = X"), "Letter")

The following example builds off the previous by calculating the cumulative sum of two columns using the same UpdateByOperation.

source = emptyTable(10).update("Letter = (i % 2 == 0) ? `A` : `B`", "X = i", "Y = randomInt(1, 11)")

result = source.updateBy(CumSum("SumX = X", "SumY = Y"), "Letter")

The following example builds off the previous by specifying two grouping columns: Letter and Truth. Thus, each group is a unique combination of letter and boolean value in those two columns, respectively.

source = emptyTable(10).update("Letter = (i % 2 == 0) ? `A` : `B`", "Truth = randomBool()", "X = i", "Y = randomInt(1, 11)")

result = source.updateBy(CumSum("SumX = X", "SumY = Y"), "Letter", "Truth")