Skip to content

Shape data

Query Datasets

A Query Dataset is a reusable SQL query over one or more Datasets and Stashes. Use one when you need joins, CTEs, window functions or shared business logic that several widgets or reports should read the same way.

Use a Query Dataset when you need:

  • Joins across Datasets and Stashes, including ones from different sources
  • Common table expressions (CTEs) and subqueries
  • Window functions, such as “latest row per ticket”
  • One definition of a metric that many widgets share

If a widget only needs to filter, group or sort one source, a Query Widget can do that on its own. See Choose how to shape data to compare Query Datasets with Modified and Joined Datasets.

How Query Datasets relate to Query Widgets

Section titled “How Query Datasets relate to Query Widgets”
Datasets and Stashes -> Query Dataset -> Query Widgets and reports

Put the cross-source logic in the Query Dataset. Each Query Widget then reads it as a single source and handles its own filtering, grouping and display. See Write the Widget Query.

  1. Go to Settings → Query Datasets and click Add Query Dataset.
  2. Type a name at the top of the editor.
  3. Choose how to start: Ask Eric, Select Source to pick a Dataset and build from it, or Edit YAML.
  4. Click Browse datasets to add each Dataset or Stash you need to sources.
  5. Write the query.
  6. Click Run preview to check the SQL and see sample rows.
  7. Click Save.

If the definition isn’t valid, the editor shows the errors and nothing is saved. Creating a Query Dataset needs the Staff or Admin role and counts toward your Dataset limit.

Action Mac Windows
Save ⌘ S Ctrl S
Run preview ⌘ ↵ Ctrl Enter
Run expanded preview ⇧ ⌘ ↵ Ctrl Shift Enter
Browse datasets ⌃ ⇧ D Ctrl Alt Shift D
Copy AI instructions ⌃ ⇧ C Ctrl Alt Shift C
Autocomplete ⌃ Space Ctrl Space
All shortcuts ⌃ ⇧ K Ctrl Alt Shift K
schemaVersion: 1
sources:
- type: dataset
alias: tickets
source: 46b0bbe8-619a-4b23-bc44-f11842775640
timezone: America/Chicago
query: |-
select *
from tickets

Keep query as the last top-level key.

Field Required What it does
schemaVersion Yes Must be 1.
sources Yes One or more Datasets or Stashes the query can read.
sources[].alias Yes The table name the query uses for this source.
sources[].type No dataset (the default) or stash.
sources[].source Yes The Dataset or Stash ID. Browse datasets fills it in.
timezone No An IANA timezone such as America/Chicago. Defaults to UTC.
materializationPolicy.mode No Kept so older definitions stay valid. live, materialized and automatic all run live now.
query Yes Read-only SQL that selects from the aliases in sources. Keep it last.

Aliases start with a letter or underscore and use only letters, numbers and underscores. Each alias must be unique.

sources can list Datasets and Stashes only. It can’t list another Query Dataset, a Modified Dataset or a Joined Dataset. To build on another Query Dataset, copy its sources and SQL into this one.

You need access to every source a Query Dataset reads, both to create it and to edit it later.

The query runs in a read-only sandbox. It can use:

  • Joins across the aliases you declared
  • CTEs and subqueries
  • Window functions
  • Aggregates, filters, sorting and limits

It can’t change data, attach other databases, or read or write files.

Select from your aliases, not from IDs. Quote column names that contain a dot, such as tickets."board.name". Many integrations name nested fields that way, and unquoted SQL reads board.name as the name field of a table called board.

This Query Dataset joins tickets with their audit trail and keeps the latest email sent on each ticket.

schemaVersion: 1
sources:
- type: dataset
alias: tickets
source: 46b0bbe8-619a-4b23-bc44-f11842775640
- type: dataset
alias: ticket_audit
source: b8b7f7ee-af37-45cf-bd4c-d4bbac616f30
timezone: America/Chicago
query: |-
with email_audit as (
select
ticket_id,
enteredDate as email_sent_at,
row_number() over (
partition by ticket_id
order by enteredDate desc
) as rn
from ticket_audit
where lower(coalesce(auditType, '')) like '%email%'
)
select
tickets.id as ticket_number,
tickets.summary as ticket_subject,
tickets."board.name" as board_name,
email_audit.email_sent_at as last_email_at
from tickets
inner join email_audit
on email_audit.ticket_id = tickets.id
and email_audit.rn = 1

Run preview checks the YAML, your access to each source, the aliases and the SQL rules, then runs the query and shows the columns and the first 100 rows. Run expanded preview loads up to 100,000 rows in a larger view. Previewing never saves anything.

A Query Dataset runs live each time something reads it, over the latest synced rows of every source. When any of its sources syncs new rows, the Query Widgets that read it refresh. A fast-syncing source doesn’t wait for a slower one.

A result can have up to 10,000,000 rows. If a row-level query would go over, aggregate in the Query Dataset or narrow its date range.

If a source breaks or the SQL stops working, the Query Dataset shows its errors and the widgets that read it show an error state. They don’t fall back to an older result.

When you save a Query Dataset that other widgets read, Shared Query Dataset Impact lists the affected widgets before anything changes. Choose Update shared to change it for all of them, or, if you have room under your Dataset limit, Save as new to leave the shared one as it is.

  • Query Widgets read it as their source.
  • Report elements can query it.
  • Filter Variables can take their dropdown options from its columns. Only saved Query Datasets you can access appear in the picker.

Classic widgets, Modified Datasets and Joined Datasets can’t read Query Datasets.

Leave dashboard filters out of the Query Dataset. A Query Dataset can’t declare Query Parameters or bind Filter Variables. When a widget should react to a Filter Variable, bind it in the Query Widget through a Query Parameter. See Filter with a Filter Variable.

Using a Query Dataset as a Filter Variable’s option source is different: it only fills the dropdown.

The whole definition is plain YAML and SQL, so it’s easy to hand to Eric or another assistant. Copy AI instructions copies a short brief with the current sources and their columns, ready to paste into a chat. Include the business question you’re answering and any preview error you see.

  • Give output columns simple names, such as board_name and ticket_count, so widgets don’t need to quote source field names.
  • Use readable aliases, such as tickets and invoices, not a and b.
  • Build in stages. Select a few columns from one source, preview, add the join, preview, then add CTEs and window functions.

The query used an unquoted dotted column such as board.name. Quote it: "board.name", or tickets."board.name" with an alias.

sources can only list Datasets and Stashes. If you include type, use dataset or stash.

Make sure the Query Dataset returns the column, with the same name the Query Widget uses.