---
title: integral() | Tiger Data Docs
description: Calculate the integral from a TimeWeightSummary
---

Since [1.15.0](https://github.com/timescale/timescaledb-toolkit/releases/tag/1.15.0)

Calculate the integral, or the area under the curve formed by the data points. Equal to [`average`](/docs/reference/toolkit/time_weight/average/index.md) multiplied by the elapsed time.

## Samples

Create a table to track irregularly sampled storage usage in bytes, and get the total storage used in byte-hours. Use the ‘last observation carried forward’ interpolation method:

```
-- Create a table to track irregularly sampled storage usage
CREATE TABLE user_storage_usage(ts TIMESTAMP, storage_bytes BIGINT);
INSERT INTO user_storage_usage(ts, storage_bytes) VALUES
    ('01-01-2022 00:00', 0),
    ('01-01-2022 00:30', 100),
    ('01-01-2022 03:00', 300),
    ('01-01-2022 03:10', 1000),
    ('01-01-2022 03:25', 817);


-- Get the total byte-hours used
SELECT
    integral(time_weight('LOCF', ts, storage_bytes), 'hours')
FROM
    user_storage_usage;
```

## Arguments

The syntax is:

```
integral(
    tws TimeWeightSummary
    [, unit TEXT]
) RETURNS DOUBLE PRECISION
```

| Name | Type              | Default | Required | Description                                                                                                                                                        |
| ---- | ----------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| tws  | TimeWeightSummary | -       | ✔        | The input TimeWeightSummary from a time\_weight() call                                                                                                             |
| unit | TEXT              | second  |          | The unit of time to express the integral in. Can be `microsecond`, `millisecond`, `second`, `minute`, `hour`, or any alias for those units supported by PostgreSQL |

## Returns

| Column   | Type             | Description                 |
| -------- | ---------------- | --------------------------- |
| integral | DOUBLE PRECISION | The time-weighted integral. |
