Skip to content

Build / Widgets

Query Widgets

A Query Widget is a widget you define with SQL. Its Query Widget Definition is YAML that holds a source, a read-only Widget Query, and a display block that turns the result into a table, chart, metric, Markdown or HTML. This page covers when to use one and how to build it. Every YAML field is on Query Widget YAML.

Use When
A classic widget A count, sum or average, a grouped chart or a simple table covers it. No SQL needed.
A Query Widget You need grouping or filtering that’s easier in SQL, values from a Query Dataset, a Markdown or HTML layout, or display options classic widgets lack.
A Query Dataset You need joins, CTEs, subqueries or window functions, or the same shaped data in several widgets. Build it first, then point a Query Widget at it.

A Query Widget reads a Dataset, a Stash or a Query Dataset. It can’t read a Modified Dataset or Joined Dataset; reshape that data in a Query Dataset instead.

Eric writes Query Widgets. In the Workspace Conversation, describe what you want to see, such as “a bar chart of open tickets by board”. Eric drafts it as a chart card you can add with Add to dashboard. With the dashboard open on the Workspace Canvas, he can add the widget to it, or change one that’s already there, directly. See Building with Eric.

Inside the Query Widget editor, Eric has a chat panel of his own that edits the definition you have open. If you don’t like his change, click Undo changes. Use New chat and Chat history in that panel to start over or pick up an earlier chat about the same widget.

You need the Staff or Admin role, permission to edit the dashboard, and access to every source the widget reads.

  1. Open the dashboard and click Edit in the Canvas Frame, then + Widget.
  2. Choose Query Widget.
  3. Pick how to start:
    • Ask Eric: describe the widget in the chat panel.
    • Select Source: pick a dataset, choose a display, set up the calculation, and click Create Preview.
    • Edit YAML: write the definition yourself.
  4. Change the definition on the Definition YAML tab, or use Quick controls for common display settings.
  5. Click Run preview or press ⌘ Enter / Ctrl Enter.
  6. Type a title in the title box at the top, then click Save or press ⌘ S / Ctrl S.

To change a Query Widget later, open its widget actions menu (⋮) and choose Edit Widget. To go back to the classic types while creating one, click Classic Widgets.

Tool What it does
Browse Datasets Picks a Dataset, Stash or Query Dataset and adds it to the definition.
Browse Filters Adds one of the dashboard’s Filter Variables as a parameter.
New Query Dataset Starts a Query Dataset beside the widget, for joins or other shaping the Widget Query can’t do.
Copy AI instructions Copies authoring guidance and your source’s columns, to paste into another AI assistant.
Schema help Opens the field reference and copyable examples.
Quick controls Edits common display settings, such as axis labels, without touching YAML. The fields depend on display.type; add more with ui.editablePaths.

The YAML editor autocompletes fields, sources and columns. Errors show the field they belong to.

Action Mac Windows
Run preview ⌘ Enter Ctrl Enter
Save ⌘ S Ctrl S
Expand preview ⌘ Shift Enter Ctrl Shift Enter
Close expanded preview Esc Esc
Autocomplete Control Space Ctrl Space
Show or hide preview Control Shift P Ctrl Alt Shift P
Browse Datasets Control Shift D Ctrl Alt Shift D
Browse Filters Control Shift F Ctrl Alt Shift F
Copy AI instructions Control Shift C Ctrl Alt Shift C
Schema help Control Shift H Ctrl Alt Shift H
All shortcuts Control Shift K Ctrl Alt Shift K

Pressing Esc in the editor asks you to press it again before it closes, so you don’t lose work.

A Widget Query is one read-only SELECT from the relation named source:

schemaVersion: 1
source:
type: queryDataset
source: 5a242d39-195c-41da-a99b-93b402a4325b
display:
type: bar
x: board_name
y: ticket_count
timezone: America/Chicago
query: |-
select board_name, count(*) as ticket_count
from source
group by board_name
order by ticket_count desc

It can filter, group, aggregate, use case, sort and limit. It can’t join, use CTEs, subqueries or unions, or change data. When you need those, put them in a Query Dataset and select from it here. Table displays show at most 1,000 rows; put larger detail in a drilldown query.

The full rules, named sources, and source-free widgets are on Query Widget YAML.

Dashboard filters don’t apply to a Query Widget on their own. You bind each Filter Variable you want as a Query Parameter.

  1. Click Browse Filters and pick the Filter Variable, or add it under parameters with a name and the Filter Variable’s ID.
  2. Reference the parameter in SQL as $name. Use in for multi-select variables and = for single-select ones.
  3. Run the preview.
parameters:
- name: board_values
filterVariable: 32b69796-14b3-48d1-a9a7-d196b91752c1
query: |-
select count(*) as ticket_count
from source
where board_name in $board_values

Selected values are passed as typed parameters, not pasted into the SQL. See Filter Variables.

Call dashboard_date_filter() with the date column the dashboard’s date filter should apply to. When no date filter is set, every row passes.

select date_trunc('day', created_at) as created_day, count(*) as ticket_count
from source
where dashboard_date_filter(created_at)
group by created_day
order by created_day

Match the helper to what the widget measures. Activity, such as tickets opened, uses the selected range. Point-in-time values, such as a balance, use dashboard_end_date() so they can include history before the range starts. On the dashboard, the widget’s calendar icon shows either the range or As of the end date. All date helpers are listed in Query Widget YAML.

Source dates are converted to the widget’s timezone before the query runs.

Add a drilldownQuery to give viewers the detail rows behind a widget. Keep its filters in line with the main query so the rows match what’s shown.

Display How viewers open drilldown
Charts and metrics Click the widget. For charts, {{ x }} in the drilldown query is the value that was clicked.
Tables Click Expand table in the footer. With cellDrilldown set, clicking a cell opens that column’s detail rows for that row.
HTML Give each panel its own detail query under drilldowns.<name>, then open it by name from the widget’s code.

A table with no drilldownQuery tells viewers no drilldown is available. Drilldown columns show raw values unless display.columnFormats formats them. See Drilldown for the fields.

Share link viewers can drill down when the link allows it. See Sharing dashboards.

An HTML widget can load libraries from approved code sites, but by default it can’t call other APIs or load images from other sites. To allow a site, request it and then have someone approve it.

  1. List each HTTPS domain under display.externalDomains, such as api.example.com, or ask Eric to add it. A widget can request up to 10.
  2. Save the widget. A blue globe icon appears in its footer: the request is waiting.
  3. Click the globe, check the domains, and click Allow. Anyone who can edit the dashboard can approve, including a Member on their own Personal Dashboard.

While the widget can reach an allowed domain, everyone who views it, including share link viewers, sees an amber globe. Point at it to see the domains. Click it to see who approved each one, or Revoke an approval.

Removing a domain from externalDomains turns its access off but keeps the approval, so adding it back turns access on again. People who can approve see a grey globe while a widget keeps approvals it no longer requests. A widget keeps at most 10 approvals. Eric can request domains but never approve them, and a copied widget needs new approval.

The preview runs when you ask for it. A saved widget runs its query for each viewer when they open the dashboard, and refreshes when:

  • a source it reads syncs new rows. For a Query Dataset source, that’s any dataset the Query Dataset reads.
  • a date its query depends on rolls over, such as the start of a new day for today.
  • a viewer changes a bound Filter Variable or the dashboard date filter.

A Markdown or HTML widget with no source or query shows no freshness dot. See Dashboards for when dashboards pause background updates.

The saved widget keeps loading. Check that the source has synced. Then open the editor and run the preview to see any definition error.

Widget Query must select from a declared source. With source, select from source. With sources, select from one alias, such as from tickets. Don’t use a source ID as a table name.

Joins are not allowed. Move the join into a Query Dataset and select from that.

Referenced table “board” not found. The column name has a dot in it. Quote it: "board.name". Better, alias it to board_name in a Query Dataset.

The display says a column is missing. The names in display must match the column names your query returns, such as value: ticket_count with count(*) as ticket_count.

display.seriesBy requires exactly one display.y column. Use one y column with seriesBy, or drop seriesBy and list several y columns.