# Link, lookup and rollup fields

Connect records across datasets, show a linked record's values, and calculate totals over linked records.

Source: https://support.rework.com/article/link-lookup-and-rollup-fields

Real business data is connected: a project belongs to a client, a deliverable belongs to a project. Typing the client's name into every project row works until someone spells it differently, and then no report adds up. Three field types solve this together:

| Type | What it does | Northwind example |
| --- | --- | --- |
| **Two-way link dataset record** | Points a record at records in another dataset, and adds the reverse link automatically | _Client_ on Projects |
| **Two-way link lookup** | Shows a value from each linked record | _Client city_ on Projects |
| **Two-way link rollup** | Calculates a number across all linked records: count, sum, average, minimum, maximum | _Hours booked_ on Clients |

Lookups and rollups are calculated when records are read. Nobody types them and they're never out of date.

> **Note:** Creating these fields needs the **App Admin** role in Datasets, like any other field. See [Add a field to a dataset](https://support.rework.com/article/add-a-field-to-a-dataset) for the basics.

## Step 1: Link two datasets

Create an internal field with the type **Two-way link dataset record** on the dataset that _belongs to_ the other one, for example on **Projects**:

- **Linked dataset**: The dataset to point at, here **Clients**.
  
- **Allow linking multiple records**: Leave it off when a project has exactly one client. Turn it on for many-to-many relations, such as a project with several vendors.
  
- **Display fields**: The values shown on each linked record's chip and in the picker.
  

Click **Create & Assign**. Two things now exist: the **Client** column on Projects, and a reverse column on Clients (named _Client (back-link)_) that lists each client's projects. Editing either side updates the other.

In the grid, a linked value shows as a chip. Click the cell to pick records from the other dataset.

![The Client link column on the Projects grid](https://storage.googleapis.com/reworkv3-public/success/260923/KyCOTZN0kBh3PzhHs0xr3bhH0g9dq6O3HDAs64XhxqXCfBf9IwQ7xpju3EJ2JEnV/img.jwKllxDLDQvMREoB7nphEkIUPzBUZVfUBM9Owq2qkCmjohbUNcdbWTgM8n4Xseuc.png)

## Step 2: Show a value from the linked record with a lookup

On **Projects**, create an internal field named _Client city_:

- **Type**: **Two-way link lookup**.
  
- **Source link field**: The link to read through, here **Client**. The dialog confirms which dataset it reads from.
  
- **Field to look up**: The field to show from that dataset, here **City**.
  

Click **Create & Assign**. Every project now shows its client's city, and it changes on its own the day the client moves.

![A lookup field reading City through the Client link](https://storage.googleapis.com/reworkv3-public/success/260923/WFRkatQRr06Ya96lTJDRDyXobqZ5EuLGaT9MwRVPXOLhP1EuyndS25DYet69Wewv/img.EOW5W7awONXZGL5bvUEuOEtkC7SSnGgoq0ARZQMiP8cBME7kTM1fsNLmcofPIra5.png)

## Step 3: Calculate across linked records with a rollup

On **Clients**, create an internal field named _Hours booked_:

- **Type**: **Two-way link rollup**.
  
- **Link source field**: The link that points at the records to aggregate, here the reverse link **Client (back-link)**. The dialog shows the linked dataset, **Projects**.
  
- **Field to rollup**: The number to aggregate, here **Estimated hours**.
  
- **Aggregate function**: **Count**, **Min**, **Max**, **Sum** or **Average**. Here **Sum**.
  

Click **Create & Assign**.

![A rollup field summing Estimated hours through the reverse link](https://storage.googleapis.com/reworkv3-public/success/260923/R7bSUbVa2SyOI2y0DNB45kY460F9KstAiyjQYRkJhhYgikxhsKgWz9a4W3JGRYdi/img.g1vzXrj8gu2GSngETVPgHcEsPCqRmR3Z4Tuajp6AA2SHKCrTnVXSenllhxAhDfeH.png)

> **Note:** **Field to rollup** lists the number fields of the linked dataset: **Integer**, **Decimal**, **Currency**, **Rating**, **Progress** and **Formula**. The list loads a moment after you choose the link source, so give it a second. If it still reads _No numeric fields in the linked dataset._, that dataset has no number field yet, so add one first.

## Step 4: Read the calculated columns

Lookup and rollup columns appear on the grid like any other field, but their cells can't be edited: change the linked records and the values follow.

![The Hours booked rollup column on the Clients grid](https://storage.googleapis.com/reworkv3-public/success/260923/FOrHXwJupBnUWs64bcFWUZ9EkkXZCcN5a5W6WNQameC6ylwrCC2GsLjMVl5o9SHf/img.CTWrv2bQsNQeN5LkanCEdnVpiKh6Nn7bfIh1zjNhZ6hbay4CvxDdE6j6zGTrsxMQ.png)

**Rollup ideas for the same data**

| On | Field | Link source | Field to rollup | Function |
| --- | --- | --- | --- | --- |
| Clients | Hours booked | Client (back-link) | Estimated hours | Sum |
| Clients | Largest project | Client (back-link) | Estimated hours | Max |
| Clients | Project count | Client (back-link) | Estimated hours | Count |
| Clients | Fees booked | Client (back-link) | Fee | Sum |

## Step 5: See how everything connects

Open the caret next to the dataset name and choose **Visualize schema**. The diagram draws every dataset involved and the relations between them. The legend separates **Two-way link** edges from **Lookup / Rollup** edges, and each field is labelled with its kind, such as _link_, _lookup_ or _select_.

It's read-only: drag the boxes to tidy the picture, then close it.

![The Visualize schema diagram of Projects and Clients](https://storage.googleapis.com/reworkv3-public/success/260923/jeSthAlrnOQUNMxaaHi2TxRbYakxG2p0puoayW8jZnDui5bJdWHByNmraCtdLPDj/img.pAYimh7JdjjaFVGUfJZWnw8rNQwl2lZAYKYfbPli7fXyhCDA49bgSybXAIaMVXF7.png)

> **Warning:** Deleting a link field breaks every lookup and rollup that reads through it. Check **Visualize schema** before unlinking a link field from a dataset.
