# $sum

{% hint style="info" %}
This function has multiple signatures
{% endhint %}

{% tabs %}
{% tab title="Signature 1" %}
`{{$sum array [format]}}`

Computes the sum of [numbers](https://docs.documint.me/templates/working-with-dynamic-data/functions-and-operators/math/broken-reference) in an [array](https://docs.documint.me/templates/working-with-dynamic-data/functions-and-operators/math/broken-reference).

#### Arguments&#x20;

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="749256e4cf85463181ee3afefe9c10b2" label="Number Array" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>array</td><td>List of numbers to sum.</td><td><span data-option="749256e4cf85463181ee3afefe9c10b2">Number Array</span></td><td>true</td></tr><tr><td>format</td><td><a href="broken-reference">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

**Example**&#x20;

{% tabs %}
{% tab title="Template" %}

```javascript
{{$sum hours_worked}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "hours_worked": [3, 6, 4, 12]
}
```

{% endtab %}

{% tab title="Result" %}
25
{% endtab %}
{% endtabs %}

####

#### **Returns**

Returns the total.
{% endtab %}

{% tab title="Signature 2" %}
`{{$sum number1 number2 [...] [format]}}`

Computes the sum of numbers passed as arguments.&#x20;

#### Arguments&#x20;

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="749256e4cf85463181ee3afefe9c10b2" label="Number Array" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>number1</td><td>The first number to sum.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>number2</td><td>The second number to sum.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>[...]</td><td>The remaining numbers to sum.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>false</td></tr><tr><td>format</td><td><a href="broken-reference">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

**Example**&#x20;

{% tabs %}
{% tab title="Template" %}

```javascript
{{$sum subtotal discount tax}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "subtotal": 150,
    "discount": -20,
    "tax": 6.50
}
```

{% endtab %}

{% tab title="Result" %}
136.5
{% endtab %}
{% endtabs %}

####

#### **Returns**

Returns the total.
{% endtab %}

{% tab title="Signature 3" %}
`{{$sum collection path [format]}}`

Computes the sum of [numbers](https://docs.documint.me/templates/working-with-dynamic-data/functions-and-operators/math/broken-reference) within a [collection](https://docs.documint.me/templates/working-with-dynamic-data/functions-and-operators/math/broken-reference) (an [array](https://docs.documint.me/templates/working-with-dynamic-data/functions-and-operators/math/broken-reference) of [objects](https://docs.documint.me/templates/working-with-dynamic-data/functions-and-operators/math/broken-reference)).

#### Arguments&#x20;

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="749256e4cf85463181ee3afefe9c10b2" label="Number Array" color="blue"></option><option value="44aa8fd70a3e417f9d7fd0c5598d7442" label="Collection" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>collection</td><td>An array of objects</td><td><span data-option="44aa8fd70a3e417f9d7fd0c5598d7442">Collection</span></td><td>true</td></tr><tr><td>path</td><td>Path to the number property on each object.</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>true</td></tr><tr><td>format</td><td><a href="broken-reference">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

**Example**&#x20;

{% tabs %}
{% tab title="Template" %}

```javascript
{{$sum items "price"}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "items": [
        { "name":"Rocket Skates", "price":160.3 },
        { "name":"Acme Glue", "price":15.6 },
        { "name":"Wing Suit", "price":699.99 },
    ]
}
```

{% endtab %}

{% tab title="Result" %}
875.89
{% endtab %}
{% endtabs %}

####

#### **Returns**

Returns the total.
{% endtab %}
{% endtabs %}
