# Rollup Field in Baserow: Aggregate Data from Linked Rows

> Compare Rollup with Lookup and Count fields, then configure sum, average, min, max, and other functions that summarize linked table rows automatically.

Source: https://opennix.org/en/docs/baserow/field-types/rollup-field/


A Rollup field runs a calculation - sum, average, count, and more - across every row linked through a Link to table field and shows the result right in the current table; this article covers how it differs from a Lookup or Count field, how to create one, and how to read the table of available functions.

![Configuring a new Rollup field in Baserow](/images/baserow/field-types/rollup-field-configure-new-field.webp)

## What a Rollup field is

A Rollup field works on top of an existing [Link to table field](/docs/baserow/field-types/link-to-table-field/). While a [Lookup field](/docs/baserow/field-types/lookup-field/) simply displays one piece of data from a linked row (an email address, say), a Rollup field runs a calculation across all the linked rows at once - a sum, an average, a minimum, a maximum, and so on.

The field is read-only: you cannot edit its value directly. It is an automatic calculation that recalculates every time the data in the linked rows changes.

## How to create a Rollup field

### Prerequisite

You need an existing [Link to table field](/docs/baserow/field-types/link-to-table-field/) in the table before you can create a Rollup field.

### Steps

1. In the table, click the `+` icon to [add a new field](/docs/baserow/fields/adding-a-field/).
2. Enter a name for the field, for example "Total Spent" or "Average Rating".
3. Select **Rollup** from the field type dropdown.
4. In the configuration panel, set three options:
   - **Link row field**: pick the [Link to table field](/docs/baserow/field-types/link-to-table-field/) that supplies the linked rows;
   - **Field to roll up**: pick the specific field in the linked table whose values you want to aggregate, for example "Order Amount";
   - **Rollup function**: pick the calculation to run, for example `sum`.
5. Click **Create**.

The new field is populated immediately with the calculation result and stays read-only from then on.

## Rollup functions

A Rollup field supports several aggregation functions. The function you pick must be compatible with the type of the field being aggregated - you can only `sum` a [Number field](/docs/baserow/field-types/number-field/), for instance.

| Function | Description | Compatible field types |
|---|---|---|
| `sum` | Adds all values together | [Number](/docs/baserow/field-types/number-field/) |
| `avg` | Calculates the average of all values | [Number](/docs/baserow/field-types/number-field/) |
| `count` | Returns the number of linked rows | Any type |
| `max` | Returns the highest value | [Number](/docs/baserow/field-types/number-field/), [Date](/docs/baserow/field-types/date-and-time-fields/), [Text](/docs/baserow/field-types/single-line-text-field/) |
| `min` | Returns the lowest value | [Number](/docs/baserow/field-types/number-field/), [Date](/docs/baserow/field-types/date-and-time-fields/), [Text](/docs/baserow/field-types/single-line-text-field/) |
| `any` | Returns true if any linked boolean value is true | [Boolean](/docs/baserow/field-types/boolean-field/) |
| `every` | Returns true if every linked boolean value is true | [Boolean](/docs/baserow/field-types/boolean-field/) |
| `stddev_sample` | Sample standard deviation | [Number](/docs/baserow/field-types/number-field/) |
| `stddev_pop` | Population standard deviation | [Number](/docs/baserow/field-types/number-field/) |
| `variance_sample` | Sample variance | [Number](/docs/baserow/field-types/number-field/) |
| `variance_pop` | Population variance | [Number](/docs/baserow/field-types/number-field/) |

### Example: customers and orders

This is the clearest way to see what a Rollup field does. Say there are two tables, and the goal is to show the **total amount each customer has spent** directly on the Customers table.

1. **Customers**: holds a "Customer Name" field.
2. **Orders**: holds "Order ID", a [Number field](/docs/baserow/field-types/number-field/) called "Order Amount", and a [Link to table field](/docs/baserow/field-types/link-to-table-field/) called "[Link] Customer".

**Solution:** on the Customers table, create a Rollup field named "Total Spent":

- **Link row field**: pick the "[Link] Customer" field;
- **Field to roll up**: pick the "Order Amount" field from the Orders table;
- **Rollup function**: pick `sum`.

The "Total Spent" field now calculates and displays the sum of every linked order for each customer automatically, for example "$150.00".

## Frequently asked questions

**What's the difference between Rollup, Lookup, and Count?** All three build on a [Link to table field](/docs/baserow/field-types/link-to-table-field/), but they solve different jobs: [Link to table](/docs/baserow/field-types/link-to-table-field/) creates the relationship between rows; [Lookup](/docs/baserow/field-types/lookup-field/) displays one specific value from a linked row, such as a customer's email; [Count](/docs/baserow/field-types/count-field/) counts the linked rows, such as "3 orders"; Rollup runs a calculation across the linked rows, such as the sum of "Order Amount".

**How is the Rollup `count` function different from a dedicated Count field?** The result is identical. The [Count field](/docs/baserow/field-types/count-field/) is a simpler, dedicated field type built for exactly that one job, while `count` in a Rollup field is just one of the many functions available there.

**Why can't a Rollup field be edited?** It is a read-only field that displays a calculation result. To change its value, change the data in the linked rows instead - add a new order, or update an existing order's amount.

## What's next

Read up on the [Link to table field](/docs/baserow/field-types/link-to-table-field/) to see how relationships between tables are built, the [Lookup field](/docs/baserow/field-types/lookup-field/) for displaying single values from linked rows, and the [Count field](/docs/baserow/field-types/count-field/) for a simple linked-row count. [Field Types Overview](/docs/baserow/fields/baserow-field-overview/) compares Rollup against every other computed field type, and [Field Configuration](/docs/baserow/fields/field-customization/) covers sorting, filtering, and hiding for any field type, Rollup included.

