# Analyse data in the Analytics workspace

> Ask your own questions of the historian or the alarm journal in the Analytics tab of Analytics and Reports - write SQL in the code editor, set the time window and parameters, read the results with their quality marked (and the "Query ignores quality" warning), chart them, keep your own saved queries, turn a query into a dataset for reports, and go further with exports, extracts across sources and the server pivot - with the limits, who may use it and the HTTP routes.

Product: eaxScada · Type: How-to guide · Editions: Pro, Enterprise
Source: https://eaxware.com/docs/eaxscada/how-to/analyse-data-in-the-analytics-workspace/
Verified against commit 4e830ea.

## Goal

Answer a question about your plant's history that no report answers yet, for example "the 10-minute averages of both reactors yesterday afternoon" or "which alarms came most often last week", without saving anything to the project. When the answer is useful to others, turn the query into a dataset that reports can use.

The **Analytics** tab of the **Analytics and Reports** workspace (Pro and Enterprise) runs your own read-only SQL over one source: the historian (`samples`) or the alarm journal (`alarm_events`, `alarm_definitions`). To join both, read them into extracts first ([Combine sources with extracts and pivot on the server](/docs/eaxscada/how-to/combine-sources-with-extracts/)). It uses the same relations, columns and quality helpers as the datasets ([Relations and columns](/docs/eaxscada/reference/analytics-and-reports/#relations-and-columns)).

You need:

- the right `analytics` (a new installation gives it to Lead_Engineer; [Grant report rights](/docs/eaxscada/how-to/grant-report-rights/));
- for **Save as dataset**, also `datasets_edit`;
- a tablet or a computer: on a phone the tab says "The analytics workspace needs a wider screen".

**A query reads as you.** It runs through the same path as a dataset of a report: your tag read rights decide which rows exist at all. A user allowed only `Plant/A/>` gets area A's rows in every count, average and join, never another area's, whatever the SQL says. The stored tables, files and table functions cannot be named. Tags your rights hide are counted, never named ([A report shows only what you may read](/docs/eaxscada/explanation/analytics-and-reports/#a-report-shows-only-what-you-may-read)). Nothing in the workspace writes a tag or sends a command.

## 1. Write the query

1. Open **Analytics and Reports > Analytics**. The tab is shown only to users who hold `analytics`.
2. Choose the **Source**: **Historian** or **Alarms**.
3. Write the SQL in the editor. It is the shared code editor in SQL mode: it completes the source's relations and columns, the quality helpers and your `$parameters`, and it marks the server's own errors at their line while you type.

   ```sql
   SELECT time_bucket(INTERVAL '10 minutes', ts) AS t, tag_path,
          avg(value) AS value, agg_quality(quality_class) AS quality_class
   FROM samples
   WHERE tag_path LIKE 'Plant/Reactor%'
   GROUP BY 1, 2
   ORDER BY 1, 2
   ```

4. Keep the quality in the result: return `quality_class` next to the values, or `agg_quality(quality_class)` in an aggregate, or keep only good samples with `WHERE quality_class = 'good'`. A query without it still runs here, but its rows are marked as not known good (step 4).

## 2. Set the time window and the parameters

- **Time window** (required): **Last hour**, **Last 24 hours**, **Today**, **Yesterday**, **Last 7 days**, or **Custom** with **From** and **To**. Every query is bound to it: the relations hold only the rows inside it. It spans at most `reports.max_window` (400 days).
- **Parameters**: each `$name` the SQL uses gets a row with its **type** (timestamp, duration, number, integer, text, bool, tag, tag list) and a **value**. A `tag` or `tag_list` value you may not read is refused before the query runs.

## 3. Run it

- **Run** (**Ctrl+Enter**) runs the whole text; **Run selection** (**Ctrl+Shift+Enter**) runs only the selected text.
- **Cancel** stops your running query: "The query was cancelled."
- The status chip says how many rows came back and how long it took ("36 rows in 48 ms"). A second chip sums up the quality ("2 uncertain", or **Query ignores quality**).

An error in the SQL is shown under the editor with its line and column ("Line 2, column 8: Unknown column ..."), and the editor marks that line, also when you ran a selection.
[Image: The Analytics tab with the Source Historian, the time window Custom from 11/04/2026 01:00 PM to 04:00 PM, and a three-line query selecting ts and no_such_column from samples. Line 2 carries a red marker, and the red line under the editor reads "Line 2, column 8: Unknown column "no_such_column" (did you mean ts?)".]
[Image: The Analytics tab with the Source Historian, the time window Custom from 11/04/2026 01:00 PM to 04:00 PM, and a three-line query selecting ts and no_such_column from samples. Line 2 carries a red marker, and the red line under the editor reads "Line 2, column 8: Unknown column "no_such_column" (did you mean ts?)".]

The server's own error, at its line and column in your text.
## 4. Read the values

The **Values** tab shows the rows in the data grid: filter and sort each column, filter all rows with **Filter rows**, and **Export CSV** (the rows in the grid). To take the whole result as a file, use **Export** in the toolbar ([Export analytics results](/docs/eaxscada/how-to/export-analytics-results/)).

**Quality is marked, never guessed.**

- When the result has a quality column (`quality_class`, else `quality`, in any case), each row carries the class the server gave it. A row the server classes **bad** or **uncertain** has a marker in the **!** column and an amber or rose accent; click the marker for the explanation ("The server classes this row as bad: at least one of its samples is bad. Do not read it as a plant value.").
- A historian query that reads `value` without its quality is answered with **Query ignores quality**: the same rule that refuses such a dataset on save. The server then marks the rows that may hold bad or uncertain samples: with a `tag_path` column, the rows of the tags that have non-good samples in the window; without one, every row when the window holds any. Their marker says **May include non-good samples** and offers **Add quality column**, which rewrites the query with the quality column.
- The chip above the grid ("2 rows not known good") filters the grid to the marked rows.
- Simulated rows carry **SIM** and a **Simulated** marker.
[Image: The Values tab of a 10-minute average query of the two reactor temperatures: the chips "36 rows in 48 ms" and "2 uncertain", a grid with the columns t, tag_path, value and quality_class (each row good), the Filter rows box, "36 rows", the chip "2 rows not known good" and Export CSV.]
[Image: The same Values tab in the dark theme.]

Each row carries the quality class the server gave it; the chip filters to the rows that are not known good.
[Image: A query "SELECT tag_path, avg(value) AS mean, max(value) AS peak FROM samples GROUP BY tag_path" with a warning marker on line 1 and the chip "Query ignores quality". The row Plant/Reactor2/Temperature has a warning marker; its open card "Warning: row 3" says "May include non-good samples: Your query does not read quality, and this tag has bad or uncertain samples in the window. Add the quality column to see which.", the save rule's fix, and an Add quality column button.]
[Image: The same query and open warning card in the dark theme.]

A query that ignores quality: the rows of tags with bad or uncertain samples in the window are marked, with the fix.
**Large results.** The workspace reads the result in pages of 10,000 rows ("Reading rows ... of ..."). A query returns at most `analytics.max_rows` rows (100,000 by default); beyond that the notice says "Only the first N rows are shown (the limit for the browser). Export the whole result as a file." Then:

- **Export the whole result** writes every row to a CSV, Excel or Parquet file on the server ([Export analytics results](/docs/eaxscada/how-to/export-analytics-results/));
- **Pivot on the server** groups the whole result on the server into row groups and a pivot column ([Pivot a large result on the server](/docs/eaxscada/how-to/combine-sources-with-extracts/#3-pivot-a-large-result-on-the-server));
- or narrow the window, group the rows, or add a `LIMIT`.

## 5. Chart it

Open **Chart** (or **Split**, beside the grid on screens 1600 pixels wide and more; the tab you used last is remembered):

1. **Chart type**: **Line**, **Bar**, **Scatter**, **Pie** or **Heatmap**.
2. **X axis**: a column, often the time.
3. **Values (Y)**: one or more number columns.
4. **Series by** (optional): a column whose values split the rows into one series each, such as `tag_path`.

A line over a time column is drawn as a trend, with zoom. Rows that are not known good are never drawn like good ones: an uncertain value is dashed, a bad one a gap with a band, and other charts draw such points hollow, dashed and faded, with the quality in the tooltip. The legend toggles series; the icons above the chart export a **PNG** and a **CSV** of the plotted data. The chart says when it draws only the first series or x values.
[Image: The Chart tab of the same 10-minute average query: Chart type Line, X axis t, Values (Y) value, Series by tag_path, a legend with Plant/Reactor1/Temperature and Plant/Reactor2/Temperature, the PNG and CSV icons, and the line of Reactor1 around 82.]
[Image: The same chart in the dark theme.]

The chart builder: one series per tag.
## 6. Save the query, or make it a dataset

- **Save query** keeps the query in **Saved queries** under a name. Saved queries are **yours**: no other user sees them, and they are not project content (not in checkpoints, project archives or HA replication). The parameters' last values are kept; the time window is not, you choose it at each run. **Open a saved query...** loads one; **Delete saved** removes your copy only. At most 200 per user.
- **Save as dataset** (needs `datasets_edit`) turns the query into a dataset that reports can use: give a **Name**, an **ID** (`ds_...`, fixed once saved), an optional **Description** and the **Tag scope** (the tag patterns it may read). The server checks it as every dataset save is checked, the quality rule included: a historian query that ignores quality is refused here, with **Add quality column**. See [Create a report dataset](/docs/eaxscada/how-to/create-a-report-dataset/).

## Limits

| Limit | Value |
|---|---|
| Rows per query | `analytics.max_rows` (default 100,000); the result is cut there and says so |
| Time per query | `analytics.query_timeout` (default 60 s) |
| Size of one result | 64 MiB |
| Time window | `reports.max_window` (default 400 days), always required |
| Running queries | `analytics.per_user` (default 1) per user, and `analytics.workers` (default 2) on the server, queries over extracts included; one more is refused ("too many queries running", `429 ANALYTICS_BUSY`), never queued |
| Results kept on the server | your last result only, for 10 minutes without reading, 16 on the server |
| Parameters | 32 per query |
| Saved queries | 200 per user |

### SQL on DuckDB 2.0

Queries, report datasets and the AI co-pilot's SQL run on DuckDB 2.0. A query written for an earlier version may need a change:

- the arrow form of a lambda, `x -> x + 1`, is refused: write `lambda x: x + 1`;
- `~` matches part of a text, not the whole text;
- an integer division or modulo by zero is an error, not NULL;
- any error inside a transaction ends that transaction.

## Who may use it

- People with the `analytics` right only. An **API token** is refused on every analytics route (`403 REPORTS_TOKEN`), and so is the **AI co-pilot**, whatever its rights (`403 REPORTS_AI`); the AI co-pilot keeps its own SQL tool in the MCP gateway.
- Through eaxCloud remote access a query is an *engineer* action.
- On Free and Starter, and after a downgrade or a licence expiry, the tab is not shown and the routes answer `403 EDITION`.
- Every query, refused and cancelled ones too, is recorded in the audit trail as `analytics.query` (category `analytics`): the SHA-256 of the SQL text (the full text goes to the server log), the parameters, the rows, the result's hash and the duration. One record per identical query per user per minute; the repeats are counted into the next record. A result whose record cannot be written is not given (`503 AUDIT_NOT_WRITTEN`).

## Going further

- **Export a whole result**, or a saved dataset, as CSV, Excel or Parquet: [Export analytics results](/docs/eaxscada/how-to/export-analytics-results/). **Export CSV** on the grid and the chart's CSV export only the rows the browser holds.
- **Query several sources together** (the historian and the alarms), and **pivot a large result on the server**: [Combine sources with extracts and pivot on the server](/docs/eaxscada/how-to/combine-sources-with-extracts/).

## Over the HTTP API

As a signed-in person with `analytics` (a browser session):

```http
POST /api/analytics/query
Content-Type: application/json

{"family": "historian",
 "sql": "SELECT tag_path, avg(value) AS v, agg_quality(quality_class) AS quality_class FROM samples GROUP BY 1",
 "parameters": [{"name": "from", "type": "timestamp", "value": "2026-11-04T13:00:00Z"},
                {"name": "to", "type": "timestamp", "value": "2026-11-04T16:00:00Z"}]}
```

- The answer holds the result's `id`, `columns`, `total_rows`, `truncated`, `sha256`, the hidden tags' count (`tags_hidden`), the quality summary (`quality_column`, `quality` counts, `ignores_quality` with `quality_reason` and `quality_fix`, `affected_rows`) and the first `page`: `rows`, `row_quality` (each row's class), `row_affected` (rows that may hold non-good samples), `next_offset` (`-1` after the last page).
- `GET /api/analytics/query/<id>?offset=&limit=` reads the next page (at most 10,000 rows); `DELETE /api/analytics/query/<id>` drops your result; another user's result answers `404`.
- `DELETE /api/analytics/query` cancels your running query; the query itself then answers `409 ANALYTICS_CANCELLED`.
- `tag_scope` (tag patterns) can narrow the tags a query reads, never widen your rights.
- An error in the SQL answers `422 REPORTS_SQL` with `message`, `line` and `column` in the text sent.
- `GET /api/analytics/queries` lists your saved queries, the limits and the sources; `PUT /api/analytics/queries/<id>` saves one (`{"name", "family", "sql", "parameters"}`), `DELETE` removes it.

The answers are listed in the [reference](/docs/eaxscada/reference/analytics-and-reports/#analytics-workspace).

## Related

- [The analytics workspace](/docs/eaxscada/explanation/analytics-and-reports/#the-analytics-workspace)
- [Create a report dataset](/docs/eaxscada/how-to/create-a-report-dataset/)
- [Grant report rights](/docs/eaxscada/how-to/grant-report-rights/)
- [Analytics and Reports reference: analytics workspace](/docs/eaxscada/reference/analytics-and-reports/#analytics-workspace)
