---
schema_version: "1"
id: 5d6b2c3bf212b227559812a103e05b229cf84afed8a3693224ab222ca8e3bc04
title: Queries and Custom Queries
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/analytics/264-0-0/bi_dashboard_steps.md
canonical_url: https://help.salesforce.com/s/articleView?id=analytics.bi_dashboard_steps.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 8f485712b145a954024bda2b2921e76f5d842f7d2647b62d1573e67efaab1bc3
description: Widgets that display data require queries. A widget displays the results returned by a query. For example, a query calculates the average opportunity amount, grouped by region. The widget displays the results in a bar chart format with each bar showing the average amount for a region.
products:
  - CRM Analytics
  - Cross Cloud
release: "264"
---
# Queries and Custom Queries

Widgets that display data require queries. A widget displays the results returned by a query. For example, a query calculates the average opportunity amount, grouped by region. The widget displays the results in a bar chart format with each bar showing the average amount for a region.

In the dashboard designer, a lens and a query are similar, but not the same. Unlike a query, a lens can be saved as a standalone asset in an app. For example, you can save a lens that displays opportunity trends as a timeline chart. We use “query” to refer to the underlying calculation used to populate a widget in a dashboard.

## Query

You can build a widget using one of the following types of queries.

Most queries are this type. The type of query is based on the data source. For instance, CRM Analytics can execute a SAQL query against one or more datasets or a SOQL query against a Salesforce object. CRM Analytics provides multiple ways to create queries.

You can use the Chart mode or Table mode of the lens on a single dataset. You can calculate measures, group results by dates and dimensions, and filter records based on dataset fields. Here’s an example of a lens-built query that populates a chart widget.

![The widget shows a chart based on the query defined in the explorer.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_dashboard_step_explorer_and_widget.png)

To create customized SAQL or SOQL queries, use the Query mode of the lens. For example, in Query mode, you can create a query based on multiple datasets. The following chart widget shows the results from the SAQL query. For more information about SAQL queries, see the [CRM Analytics SAQL Developer Guide](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-intro.html).

![The widget shows a chart based on the SAQL query.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_dashboard_step_saql_editor_and_widget.png)

CRM Analytics creates different query types based on the widget type. Some query types have a limit on the number of results that they can return. For more information about all query types, including those not available in the lens, see the [CRM Analytics Dashboard JSON Reference](https://developer.salesforce.com/docs/analytics/bi-dev-guide-json/guide/).

## Custom Query

A custom query is more rare. It doesn’t run calculations on your data. Instead, the query provides a static list of user-defined values. For example, a toggle widget can show static values "$," "#" and "AVG." To make the toggle widget interact with other widgets in the dashboard, use data source linking to connect the custom query with other faceted queries. Or bind the static values to the queries of other widgets in your dashboard. For instance, you can bind "$" and "#" to show different measures: "$" to show the value of opportunities, and "#" to show the number of opportunities. In this example, "$" is selected in the toggle widget, and the dashboard shows the value of opportunities.

![Dashboard with a static step](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_dashboard_static_step_widget.png)

#### See Also

- [Manage Queries for Widgets](https://help.salesforce.com/s/articleView?id=analytics.bi_dashboard_steps_create.htm&release=264.0.0&type=5 "Queries return results that are displayed in widgets. For example, a number widget displays the result of a calculation that is defined in a query. Queries can be built on a data source, like a dataset or a Salesforce object. They can also be “custom queries” created with user-defined values.")
- [Create a Query with a Lens](https://help.salesforce.com/s/articleView?id=analytics.bi_dashboard_step_build.htm&release=264.0.0&type=5 "Manually create a query from the dashboard designer when you’re concerned about the results it returns and not the widget that displays those results. For example, you might build a query that calculates three measures. You can display all measures in a combo chart and display each measure in a separate number widget as well. You can reuse queries in multiple widgets.")
- [Create a Query with the Query Editor](https://help.salesforce.com/s/articleView?id=analytics.bi_dashboard_step_saql_build.htm&release=264.0.0&type=5 "Use the query editor to create or customize SAQL or SOQL queries. The query editor gives you additional flexibility over queries created by widget wizards or in the chart and table modes of the lens.")
- [Create a Custom Query with User-Defined Values](https://help.salesforce.com/s/articleView?id=analytics.bi_dashboard_steps_custom_flex.htm&release=264.0.0&type=5 "Use custom queries to apply user-defined values to dimensions, measures, and limits of other queries. For example, you can create a toggle widget that filters case records based on the following user-defined values: High Priority Cases, Medium Priority Cases, and Low Priority Cases. To enable these custom values to filter your data, you map them to your data using a binding.")