# Formula - Sum

The `sum(...)` Formula function, as the name implies, can be used to summarize any number of values (integer, float, double, ...).

## Quick example

Let's get you started with the following simple example. For other, and more advanced examples, please scroll down on this page to the Examples section.

Input Expression Result
``````
[{"value":1}, {"value":3}]

``````
``````
sum(jsonpath('\$..value', body))

``````
4
Text Data sum expression Unique values

## Features

`sum( )` function can be used as long as there is valid `Content` parameter, it doesn't matter if the content parameter are extracted values from XML,JSON or even CSV.

• Return the addition result of extracted values from the Content.
• Can be applied to any valid Content that return data as valid numbers, review Formula user guide for the complete list of functions.

This plugin loads the entire message into RAM, so make sure to apply this function only on small messages.

## How to use

To use the sum function, the Content parameter should contain data (otherwise it will fail and you will end up with nothing). But first and foremost we have to configure the Formula plugin:

• Select Formula as the expression type plugin.
• Write down the expression to use in the 'Expression' text area.
• Input proper Content as a parameter to the function.

### Syntax

Use the sum function with any of the following parameters:

• From Message Body: `sum(body)`

• From Message Context: `sum(context('MessageContextKey'))`

• Result from previous Formula operation `sum(SomeOtherNestedFormulaFunction(Content))`

## Examples

Below, you will find different common examples of how to use the sum function.

### Body as Content

Number 2 is the body content, by using the provided expression, the result is `2`.

e.g. `sum(body)` #### Message Body

``````
2

``````

#### Expression

``````
sum(body)

``````

### Context as Content

Number 4 is the value for the corresponding key "id", by using the provided expression, the result is `4`.

e.g. `sum(context('id'))` #### Message Context Value

``````
id

``````

#### Expression

``````
sum(context('id'))

``````

### Formula Function as Content

The message body is a JSON structure, and by using the provided expression, the result is `6`. e.g. `sum(jsonpath('a[*].b', body))` #### Message Body

``````
{a:[{b:'1'},{b:'2'},{b:'3'}]}

``````

#### Expression

``````
sum(jsonpath('a[*].b', body))

``````

## Next Step

Expression Type Plugins are used in Search Fields
What are Search Fields?
What are Search Field Expressions?
What are Message Types?
What are Log Views?