How a Query Library Keeps Every Chart on the Same Number

A query library is a shared place for the queries a team has checked and published. Charts reuse them instead of carrying their own SQL, so the same metric gives the same number everywhere.

How a Query Library Keeps Every Chart on the Same Number

Two charts in the same product are both labelled "On-time delivery". One shows 94%. The other shows 91%.

Neither chart is broken. Each one was built with its own SQL, by a different person, in a different month, and the two queries treat a late delivery slightly differently.

A query library removes the second copy. The query is written once, checked and published, and every chart that needs the metric uses that one query.

What is a query library?

A query library is a shared catalog of queries that a team has checked and published for reuse. Each entry has a name, a description and a version history. A chart points to an entry in the library and does not hold its own copy of the SQL.

Three things separate it from a folder of saved SQL files:

  • Status. A query is either a draft or published. Only published queries can be used in charts.
  • Versions. Every publish creates a new version, and the earlier ones are kept.
  • A link, not a copy. The chart refers to the query. A correction is made in one place.

Why do charts on the same data disagree?

In most analytics tools, each chart carries its own query. Someone builds the first chart, someone else copies its SQL for a second one and adjusts it, and from that moment the two can drift apart.

The differences are usually small and reasonable:

  • one query leaves out cancelled orders and the other does not;
  • one counts by order date and the other by delivery date;
  • each uses a different timezone for "today";
  • a later fix reached the original chart and not its copies.

The more charts there are, the more copies there are. In a product that serves many customers, the count grows again, because every customer has dashboards of their own.

One reusable query feeding three places. On the left, a query library holds a published query named On-time delivery, version 3, described as deliveries that arrived by the promised time as a share of all deliveries. Three arrows lead from it to the right: a KPI tile showing 94 percent for last month, a trend chart of the same metric over time, and an AI chat where a customer asks how on-time delivery was last month and is told 94 percent, up from 91 percent the month before. The SQL is written once in the library and all three read it.
One query behind the KPI tile, the trend chart and the AI chat.

How does a query library work?

The life of a reusable query has five steps.

  1. Write. Someone who knows the data writes the query and saves it as a draft.
  2. Check. The result is compared with a number the business already trusts, such as last month's invoice total.
  3. Publish. The query becomes version 1 and appears in the library for others to use.
  4. Reuse. Charts attach the published query. Each chart still chooses its own grouping, filters and chart type.
  5. Change. An edit is published as version 2. Charts stay on the version they were built with and show that an update is available. Someone decides when each chart moves.

Step 5 matters most. Without it, a change to a shared query changes every dashboard at once, including the ones your customers open every morning. With it, a change to a definition is a decision someone makes, chart by chart or all together. More on this in versioning embedded analytics.

A reusable query named On-time delivery with two published versions. Version 2, the latest, was published today and counts a delivery as late after the promised hour. Version 1 was published in March and counts a delivery as late after the promised day. Chart A uses version 2. Chart B still uses version 1 and carries an Update available label, showing that a new version does not change a chart until someone moves the chart to it.
A new version does not change a chart until someone chooses it.

Is a query library the same as a semantic layer?

No. Both exist so that a metric has one definition, and they go to different depths.

Query librarySemantic layer
What you defineFinished queriesMeasures, dimensions and how tables join
Who writes the SQLA person, once per queryThe layer, for each request
How flexible it isEach query answers the questions it was written forAny valid combination of measures and dimensions
Effort to startLow: it uses the SQL you already haveHigher: the data has to be modelled first

A semantic layer is the more complete answer and the larger project. A query library is the smaller step, and the list of checked queries is a good starting list of metrics if you build a semantic layer later. The guide to a semantic layer for embedded analytics covers that route.

Why does it matter more when customers build their own charts?

Inside a company, two dashboards that disagree cost a meeting. In a product that shows analytics to its own customers, the customer sees the two numbers and concludes that the product is wrong.

The risk grows when customers build charts themselves. They cannot be expected to write correct SQL against your database, and they should not be able to. A query library gives them something safer to build from. The customer chooses the metric, the breakdown, the period and the chart type. The calculation is the one your team published.

That is the difference between self-service that creates support tickets and self-service analytics that customers can rely on.

A query library is one of two controls, and it does not replace the other. The library makes sure every customer gets the same calculation. A separate rule, applied on the server, makes sure each customer sees only their own rows. See multi-tenancy and row-level security.

What does it change for AI questions?

An AI assistant that writes SQL from nothing has to guess which column means revenue and how the tables join. A library gives it queries that someone has already checked.

That leaves a choice about how strict to be:

  • Approved queries only. The assistant answers from published queries. It can answer fewer questions, and every number comes from a query a person has checked.
  • New queries, checked before they run. The assistant may write a new query, and the system checks it before running it. It can answer more questions, but no person has checked the calculation.

Which one fits depends on what customers do with the number. A figure that ends up on an invoice needs the first.

What a query library does not fix

  • Wrong data. If the source data is late or duplicated, every chart is wrong in the same way.
  • What a metric should mean. Someone in the business still has to decide whether a cancelled order counts, and own that decision.
  • Too many queries. A library with 400 near-identical queries is the old problem with a search box. It needs an owner, clear names and a habit of retiring what is no longer used.
  • A slow query. Reuse does not make an expensive query cheaper to run.

How the Query library works in Sumboard

Sumboard released its Query library in November 2026.

  • Folders, search and status. Queries sit in folders. You can search by name or description, and each query shows whether it is a draft, published, or has unpublished changes.
  • Versions. Every publish creates a new version. Charts stay on their version and show when an update is available.
  • Tenant rules apply to every query. The safeguards set on a data source apply to every reusable query. If a safeguard cannot be applied, Sumboard blocks running and publishing the query and says why.
  • Use in any chart. You attach a published query to a chart in the chart editor and build on top of it.
  • The SQL that runs is visible. The editor shows the query you wrote and the exact SQL sent to your database.
  • One run for several charts. When several charts on a dashboard use the same query, Sumboard runs it once.
  • Ask uses it too. Ask, the plain-language question box for your customers, can be set to use only approved queries, or to write new queries that are checked before they run.

The Query library is included in every plan, including Free. See pricing and the changelog.

Where to start

Pick the five metrics that appear in the most charts. For each one, find every copy of its query, compare them, agree on one, publish it and point the charts at it.

Comparing the copies is usually where the old disagreements come to light, and that is the useful part of the exercise.

Ready to launch customer-facing analytics?

Let your customers build their own dashboards inside your product. They see only their own data, and every number comes from a query you approved.

Frequently asked questions

What is a query library in analytics?

▾
A query library is a shared catalog of queries that a team has checked and published for reuse. Each query has a name, a description and a version history. Charts refer to a query in the library and do not carry their own copy of the SQL, so the same metric is calculated the same way in every chart.

What is the difference between a query library and a semantic layer?

▾
A query library stores finished queries that people wrote. A semantic layer stores the definitions of measures, dimensions and joins, and writes the query itself for each request. A query library is quicker to start because it uses the SQL a team already has. A semantic layer is more flexible and takes more work to build.

What happens to dashboards when a reusable query changes?

▾
In a library with versions, nothing changes until someone chooses it. Publishing an edit creates a new version. Charts stay on the version they were built with and show that an update is available, so a change to a definition never alters a customer's dashboard without a decision.

Does a query library replace tenant filtering or row-level security?

▾
No. A query library makes sure everyone gets the same calculation. Tenant filtering makes sure each customer sees only their own rows. They are separate controls, and a customer-facing product needs both.

Written by

Nicolae Guzun

Nicolae Guzun

Founder & CEO, Sumboard

Ship analytics faster

Build customer-facing dashboards with Sumboard.

Get started for free