> ## Documentation Index
> Fetch the complete documentation index at: https://getlago.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Sum

> Add the values of an event property during a billing cycle.

`Sum` adds the values of an event property during a billing cycle. Use it when each event reports an additional quantity, such as tokens consumed or data transferred.

![Diagram of the Sum aggregation, adding up the values of a property](https://mintcdn.com/lago-docs/x0ux42rCkjpwz1jk/guide/images/sum.png?fit=max\&auto=format\&n=x0ux42rCkjpwz1jk\&q=85\&s=b479a67d98f6b90a1a96e513116d8d57)

Sum calculation method

## Configure the metric

Set `field_name` to the event property you want to measure.

Choose what happens when a billing cycle ends:

* `recurring: true`: Lago keeps the quantity and carries it into the next cycle.
* `recurring: false`: Lago resets the quantity, so each cycle starts fresh.

See [Metric recurrence](https://getlago.com/docs/v2/guide/billable-metrics/recurring-vs-metered.md).

## Create the metric

> [tab] Dashboard
>
> 1. Go to **Billable metrics** in the side menu.
> 2. Create a new billable metric.
> 3. Enter a name, a code and an optional description.
> 4. Select **Sum** as the aggregation type.
> 5. Choose whether the measured quantity carries over or resets at the end of each billing cycle.
> 6. Select the event property you want to measure.
> 7. Add filters if you want to group usage by dimensions such as region or provider.
> 8. Click **Add billable metric**.

> [tab] API
>
> ```bash theme={"dark"}
> LAGO_URL="https://api.getlago.com"
> API_KEY="__YOUR_API_KEY__"
>
> curl --location --request POST "$LAGO_URL/api/v2/billable_metrics" \
>   --header "Authorization: Bearer $API_KEY" \
>   --header 'Content-Type: application/json' \
>   --data-raw '{
>       "billable_metric": {
>         "name": "API requests",
>         "code": "api_requests",
>         "description": "Total number of API requests.",
>         "aggregation_type": "sum_agg",
>         "field_name": "total_requests",
>         "recurring": false
>       }
>     }'
> ```

## Calculation example

The two example events below belong to `contract_example` and the same billing cycle. Their timestamps are January 16 and 17, 2027 at 00:00 UTC.

```json Event 1 theme={"dark"}
{
  "transaction_id": "transaction_1",
  "external_contract_id": "contract_example",
  "code": "api_requests",
  "timestamp": 1800057600,
  "properties": {
    "total_requests": 20
  }
}
```

```json Event 2 theme={"dark"}
{
  "transaction_id": "transaction_2",
  "external_contract_id": "contract_example",
  "code": "api_requests",
  "timestamp": 1800144000,
  "properties": {
    "total_requests": 10
  }
}
```

The events report 20 and 10. Lago adds them: 20 + 10 = 30.

> [card] [Aggregation examples](https://getlago.com/docs/v2/guide/billable-metrics/aggregation-types/aggregation-examples.md)
>
> Compare how aggregation types calculate usage.

> [card] [Metered products](https://getlago.com/docs/v2/guide/product-catalog/metered-products.md)
>
> Connect your metric to a Product.

> [card] [Create a billable metric (API)](https://getlago.com/docs/v2/api-reference/billable-metrics/create.md)
>
> `POST /billable_metrics`

> [card] [Ingest usage](https://getlago.com/docs/v2/guide/events/ingesting-usage.md)
>
> Send usage events to Lago.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.