---
schema_version: "1"
id: 090a2cb2c14ecf3d9d3cbba6ac79f5fea5adfecf22af947a175e1f70a1380cb1
title: Create a Query with a Lens
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/analytics/264-0-0/bi_dashboard_step_build.md
canonical_url: https://help.salesforce.com/s/articleView?id=analytics.bi_dashboard_step_build.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: f3173ab610f2e8130cc62e3d1116a605e712c61435d25ec1a891d30a88ea5b20
description: 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.
products:
  - CRM Analytics
  - Cross Cloud
release: "264"
---
# Create a Query with a Lens

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.

For information about clipping a lens to create a query, see [Clip a Lens to a Dashboard](https://help.salesforce.com/apex/HTViewHelpDoc?id=bi_explorer_clip_lens.htm&language=en_US).

1. To open the queries panel, click an empty space in the dashboard canvas in the dashboard designer.
    
    ![The steps panel shows the steps defined in the dashboard.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_dashboards_steps_panel.png)
2. If the queries panel has existing queries organized in sections, click ![Add Step button](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/Add_Step_button.png) next to the a section to create a query of that type.
    
    For example, click ![Add Step button](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/Add_Step_button.png) next to the Static section to create a custom query. This feature is available for all section types, except `Apex`, `Soql`, and multiple-dataset queries.
3. Click **Create Query**.
    
    ![The Select a Dataset screen shows a list of all fields in the dataset.](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_widget_select_a_dataset_includes_static_option.png)
4. Click **Dataset** for a CRM Analytics dataset or **Salesforce Direct** for a Salesforce object.
5. Select the dataset or Salesforce object that contains the data that you want to include in the query. Enter the name in the search box if your data source isn’t easy to find.
    
    The lens appears showing the default measure, Count of Rows.
    
    ![The explorer shows Count of Rows, by default, after you select a dataset.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_dashboards_explorer_default_bar_chart.png)
6. In the lens, click **Untitled Query** and enter the query label.
    
    CRM Analytics creates the query ID from the label. After you create the query, you can’t change the query ID. CRM Analytics refers to queries by their ID so dashboards don’t break if you change the labels.
7. To add a measure, click **+** under the Bar Length field.
    
    The Count of Rows measure shows, by default. To change a measure, click the measure and then choose a new one.
    
    You can add as many measures as needed.
8. To group the measures by a date or dimension, click **+** under Bars, and then select the field.
    
    You can add multiple groupings. To change a grouping, click the grouping and select a new field. To reorder or delete a grouping, click the down arrow to the right of the grouping and then select the option.
9. To add a filter, select **Filters**, click **+** under Filters, and then select the field to filter by.
    
    You can add multiple filters.
10. To change the chart or table type for the query, click ![Chart Mode button](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_explorer_change_chart_type_button.png) or ![Table Mode button](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_table_mode_button.png), respectively.
11. To set the widget properties at the query-level, click ![Properties button](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_button_formatting.png).
    
    ![The chart properties appear in the right pane.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_dashboards_step_chart_properties.png)
12. To write a custom SAQL or SOQL query, click ![SAQL Mode button](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_saql_mode_button.png).
    
    For more information, see [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.").
13. Click **Done**.
    
    CRM Analytics adds the query to the query panel, making it available for use by other widgets in the dashboard.
    
    ![Tip](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/images/icon_tip.png)
    
    Tip If you drag the query to the dashboard designer canvas, CRM Analytics displays the query results as the chart specified while creating the query. To display the widget differently in the dashboard than what was specified at the query level, select the widget in the dashboard and then set the widget properties. The widget properties override the query settings.
14. Save the dashboard.

- **[Tips for Salesforce Direct Data Queries](https://help.salesforce.com/s/articleView?id=analytics.bi_dashboard_step_sf_direct_limitations.htm&release=264.0.0&type=5)**  
    Direct Data is an option for querying live Salesforce data without having to set up replication or create datasets. With Direct Data, you can query Salesforce objects in the dashboard designer’s explorer and edit Salesforce Object Query Language (SOQL) queries in the query editor.

#### See Also

- [Query Properties for Analytics Dashboard](https://help.salesforce.com/s/articleView?id=analytics.bi_dashboard_step_properties_flex.htm&release=264.0.0&type=5 "Query properties define the query that returns results to display in the widget. These properties also specify how the widget behaves and interacts with other widgets in the CRM Analytics dashboard. The properties apply to dashboards created in the dashboard designer only.")