apoc.coll.runningTotal

Details

Syntax

apoc.coll.runningTotal(list)

Description

Returns an accumulative LIST<INTEGER | FLOAT>.

Arguments

Name

Type

Description

list

LIST<INTEGER | FLOAT>

The list to return a running total from.

Returns

LIST<ANY>

Usage examples

The following examples return a list containing the running total of all previous values using both APOC and Cypher:

apoc.coll.runningTotal
WITH [1,3,5,7,9] AS list
RETURN apoc.coll.runningTotal(list) AS output
Using Cypher’s reduce()
WITH [1,3,5,7,9] AS list
RETURN reduce(cumL = [head(list)], x IN tail(list) | cumL + (last(cumL) + x)) AS output
Results
output

[1, 4, 9, 16, 25]