# sum

Calculates the sum of all numeric values in an array. Non-numeric values are ignored.

```liquid
{% assign total = prices | sum %}
{% log total %}
```

#### Syntax

```liquid
{{ array | sum }}
```

| Parameter | Description            |
| --------- | ---------------------- |
| `array`   | Array of values to sum |

#### Return Value

Returns a number — the sum of all numeric values in the array. Non-numeric values are skipped.

#### Examples

**Sum order line item prices:**

```liquid
{% assign prices = order.line_items | map: "price" %}
{% assign total = prices | sum %}
{% log "Total: $" | append: total %}
```

**Sum quantities:**

```liquid
{% assign quantities = line_items | map: "quantity" %}
{% assign total_items = quantities | sum %}
{% log "Total items: " | append: total_items %}
```

**Sum values from a CSV import:**

```liquid
{% assign rows = file.content | parse_csv %}
{% assign amounts = rows | map: "amount" %}
{% assign total = amounts | sum %}
{% log "Import total: " | append: total %}
```

**Calculate total weight:**

```liquid
{% assign weights = order.line_items | map: "grams" %}
{% assign total_grams = weights | sum %}
{% assign total_kg = total_grams | divided_by: 1000.0 %}
{% log "Total weight: " | append: total_kg | append: " kg" %}
```

**Sum with mixed data (non-numeric values are ignored):**

```liquid
{% assign values = "10,abc,20,30,n/a" | split: "," %}
{% assign total = values | sum %}
{% log total %}
```

Output:

```
60
```

#### Notes

* Non-numeric values (strings, nulls, etc.) are silently skipped
* Values are parsed as floats, so decimal numbers are supported
* Combine with `map` to sum a specific property from an array of objects
* Returns `0` for an empty array


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.datajet-app.com/liquid/filters/sum.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
