Saved queries
Saved queries are a way to save commonly used queries in MetricFlow. You can group metrics, dimensions, and filters that are logically related into a saved query.
Exports and saved queries comparison
Saved queries are distinct from exports, which schedule and execute saved queries using dbt Cloud's job scheduler. The following table compares the features and usage of exports and saved queries:
Feature | Exports | Saved queries |
---|---|---|
Availability | Available on dbt Cloud Team or Enterprise plans on dbt versions 1.7 or newer. | Available in both dbt Core and dbt Cloud. |
Purpose | To write saved queries in your data platform and expose metrics and dimensions as a view or table. | To define and manage common Semantic Layer queries in YAML, which includes metrics and dimensions. |
Usage | Automatically runs saved queries and writes them within your data platform. Exports count towards queried metrics usage. Example: Creating a weekly aggregated table for active user metrics, automatically updated and stored in the data platform. | Used for organizing and reusing common MetricFlow queries within dbt projects. Example: Group related metrics together for better organization, and include commonly used dimensions and filters. |
Integration | Must have the dbt Semantic Layer configured in your dbt project. Tightly integrated with the MetricFlow Server and dbt Cloud's job scheduler. | Integrated into the dbt DAG and managed alongside other dbt nodes. |
Configuration | Defined within the saved_queries configuration. Set up within the dbt Cloud environment and job scheduler settings. | Defined in YAML format within dbt project files. |
All metrics in a saved query need to use the same dimensions in the group_by
or where
clauses. The following is an example of a saved query:
Parameters
To define a saved query, refer to the following parameters:
All metrics in a saved query need to use the same dimensions in the group_by
or where
clauses.
When using the Dimension
object, prepend the semantic model name, for example Dimension('user__ds')