> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-3a82795f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Sums the arithmetic difference between consecutive rows.

# deltaSum

<h2 id="deltaSum">
  deltaSum
</h2>

Introduced in: v21.3.0

Sums the arithmetic difference between consecutive rows.
If the difference is negative, it is ignored.

<Tip>
  The underlying data must be sorted for this function to work properly.
  If you would like to use this function in a [materialized view](/reference/statements/create/view#materialized-view), you most likely want to use the [`deltaSumTimestamp`](/reference/functions/aggregate-functions/deltaSumTimestamp) function instead.
</Tip>

See also:

* [`runningDifference`](/reference/functions/regular-functions/other-functions#runningDifference)

**Syntax**

```sql theme={null}
deltaSum(x1[, x2, ...])
```

**Arguments**

* `x1[, x2, ...]` — One or more input values. [`Integer`](/reference/data-types/int-uint) or [`Float`](/reference/data-types/float)

**Returned value**

Returns a gained arithmetic difference of the input values. [`(U)Int*`](/reference/data-types/int-uint) or [`Float*`](/reference/data-types/float)

**Examples**

**Basic usage with positive differences**

```sql title=Query theme={null}
SELECT deltaSum(arrayJoin([1, 2, 3]))
```

```response title=Response theme={null}
┌─deltaSum(arrayJoin([1, 2, 3]))─┐
│                              2 │
└────────────────────────────────┘
```

**Mixed values with negative differences ignored**

```sql title=Query theme={null}
SELECT deltaSum(arrayJoin([1, 2, 3, 0, 3, 4, 2, 3]))
```

```response title=Response theme={null}
┌─deltaSum(arrayJoin([1, 2, 3, 0, 3, 4, 2, 3]))─┐
│                                             7 │
└───────────────────────────────────────────────┘
```

**Float values**

```sql title=Query theme={null}
SELECT deltaSum(arrayJoin([2.25, 3, 4.5]))
```

```response title=Response theme={null}
┌─deltaSum(arrayJoin([2.25, 3, 4.5]))─┐
│                                2.25 │
└─────────────────────────────────────┘
```

**See also**

* [`runningDifference`](/reference/functions/regular-functions/other-functions#runningDifference)
