# cumsum() Function & Examples

Use the cumsum() statistics function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## cumsum

#### cumsum(a, b, c, ...)

#### cumsum(A)

Try it yourself:

```calculio
cumsum(2, 3, 4, 1)
cumsum([2, 3, 4, 1])
cumsum([1, 2; 3, 4])
cumsum([1, 2; 3, 4], 1)
cumsum([1, 2; 3, 4], 2)
```

[max](https://calcul.io/function/max/index.md)

[mean](https://calcul.io/function/mean/index.md)

[median](https://calcul.io/function/median/index.md)

[min](https://calcul.io/function/min/index.md)

[prod](https://calcul.io/function/prod/index.md)

[std](https://calcul.io/function/std/index.md)

[sum](https://calcul.io/function/sum/index.md)

[variance](https://calcul.io/function/variance/index.md)

---

## Build running totals with cumsum

**cumsum(a, b, c, ...)** returns cumulative sums. Instead of producing one total, it records the running total after each supplied value. For inputs 2, 3, and 5, the result is 2, 5, 10.

## When running totals help

Cumulative sums are ideal for spending balances, accumulated distance, frequency distributions, and time-series progress. Compare [sum](https://calcul.io/function/sum/index.md), which returns only the final total. A cumulative sequence can be paired with [diff](https://calcul.io/function/diff/index.md) to recover successive changes, subject to the usual initial-value convention.

## Examples

Use `cumsum(4, -1, 6)` to see a balance move from 4 to 3 to 9. With a vector or matrix, the function follows its supported collection semantics, so inspect the result shape with [size](https://calcul.io/function/size/index.md). If source values require preparation, use [map](https://calcul.io/function/map/index.md) for a transformation or [filter](https://calcul.io/function/filter/index.md) to retain qualifying entries.

## Input and precision caveats

Each input should be numeric or compatible with addition. A running total preserves every intermediate rounding effect, so long floating-point sequences can differ slightly from an exact symbolic total. Keep units consistent—adding dollars to percentages is meaningless—and validate missing data before accumulation. For an average that evolves with observations, combine the cumulative total with [count](https://calcul.io/function/count/index.md) rather than dividing by a fixed number.

[All functions](https://calcul.io/functions/index.md)
