<!-- Shared and derived datasets -->
<!-- canonical: https://plainwater.ai/en/wiki/dashboards/datasets -->
# Shared and derived datasets

In Plainwater AI a dataset is an **object of its own** belonging to the customer, separate from any dashboard. It has a
name, versions, a refresh schedule and a retention period. Dashboards refer to datasets by name. A number such as
"revenue per hour" therefore exists in one place, and every dashboard calculates with the same definition.

## Two kinds

| Kind | What it is | Language |
| --- | --- | --- |
| **Query dataset** | One query on one source | T-SQL or DAX |
| **Derived dataset** | One `SELECT` over other datasets | DuckDB SQL |

A query dataset fetches data from a source, such as an Azure SQL database or a Power BI model. A derived dataset combines
datasets that already exist. It does not touch the source itself. A derived dataset is an object of its own as well, so
every calculation can be reused.

## Why datasets sit apart from dashboards

Say you have a *Finance* dashboard and a *Productivity* dashboard. Now you want an overview with revenue per hour worked.
If the queries live inside the dashboards, you copy them. Then you have two definitions that drift apart, and each copy
refreshes against the source separately.

With shared datasets it goes like this:

1. The dataset `revenue_per_month` already exists and is used by *Finance*.
2. The dataset `hours_worked_per_month` already exists and is used by *Productivity*.
3. A derived dataset `revenue_per_hour` divides the first by the second.
4. The overview refers to all three.

If the definition of revenue changes, it changes in one place and all three dashboards follow.

## Approved when saved

A query is checked when it is saved, not only when it runs. T-SQL goes through the same check as free SQL on a source:
the platform parses the query and refuses when in doubt. A dataset has no parameters and never runs live; it refreshes on
its schedule and the result is stored encrypted.

:::warning Names are fixed
A dataset's name is unique per customer and cannot be changed. Dashboards refer to it by name: a rename would silently
redirect such a reference. If you no longer want a dataset, disable it. Deleting only works once no dashboard, draft or
other dataset refers to it.
:::

## Versions and drafts

Every change creates a new version; old versions remain. During a conversation the agent works on a draft. Only on save
does the draft become a version. A preview of a draft is encrypted too and belongs to that one draft.

## Example

A housing association has rental income in its finance system and the number of rental units in its property system.
The agent creates a query dataset on each source and a derived dataset that calculates rent per unit per quarter. Three
dashboards use that derived dataset: the board report, the portfolio overview and a benchmark page. When the controller
decides vacancy should count differently, the agent changes one dataset. From the next refresh, all three dashboards
follow.

:::tip Read on
- [Dashboards that keep running](https://plainwater.ai/en/wiki/dashboards/dashboards)
- [Sources and connectors](https://plainwater.ai/en/wiki/bronnen/overzicht)
:::
