home User Guide Getting Started Help Center Documentation Community Training Certification
menu
close
settings
Looker keyboard_arrow_down
language keyboard_arrow_down
English
Français
Deutsch
日本語
search
print
query

This page refers to the query parameter that is part of an Explore.

query can also be used as part of an aggregate table, as described on the aggregate_table parameter documentation page.

Usage

explore: explore_name {
  query: query_name {
    dimensions: [dimension1, dimension2, … ]
    measures: [measure1, measure2, … ]
    label: "Display Name in Field Picker"
    description: "Information about this query"
    pivots: [dimension1, dimension2, … ]
    sorts: [field1: asc, field2: desc, … ]
    filters: [field1: "value1", field2: "value2", … ]
    limit: 100
  }
  …
}

Hierarchy

query

Default Value

None

Accepts

The name of the query and subparameters to define the query

Definition

You can use the query parameter to create modeled analyses for an Explore. The modeled analyses are listed in the Quick Start section of a blank Explore, or in the Quick Start pop-up after an Explore has already been run. See the Example section on this page for how it works.

Modeled analyses are extremely helpful to beginner Looker users, since you can specify elements like the dimensions, measures, filters, and pivots that may be the most relevant and insightful.

Defining a query in LookML

Instead of creating the query’s LookML from scratch, you can use an Explore to create the query’s base LookML for you. For details, see the next section, Getting query LookML from an Explore.

The query parameter has the following subparameters:

Parameter Name Description Example
label Optionally, adds a label for the query. The label is what is displayed in the Explore’s field picker for the query. label: "Weekly Sales Totals"
description Optionally, adds a description about this query to inform your users. In the Explore, any queries with a description will have an information icon. The description text is displayed when a user hovers over the information icon.
description: "Total value of all sales per day"
dimensions A comma-separated list of the dimensions from the Explore to be included in your query. The dimensions field uses this syntax:
dimensions: [dimension1, dimension2, ...]
dimensions:
  [orders.created_month, orders.country]
measures A comma-separated list of the measures from the Explore to be included in your query. The measures field uses this syntax:
measures: [measure1, measure2, ...]
measures:
  [orders.count]
filters Optionally, adds filters to a query. Filters are added to the WHERE clause of the SQL that generates the query.
The filters field uses this syntax:
filters: [field_name_1: "value1", field_name_2: "value2", ...]
filters: [orders.country: "United States", orders.state: "California"]
limit Optionally, specifies the row limit of the query. limit: 10
sorts Optionally, specifies sort fields and sort direction (ascending or descending) for the query.
The sorts field uses this syntax:
sorts: [field1: asc|desc, field2: asc|desc, ...]
sorts: [order_items.total_sales: asc]
pivots Optionally, pivots the results on the specified fields. The pivots field uses this syntax:
pivots: [field1, field2, ...]
pivots: [created_quarter]
timezone not supported The timezone parameter is not supported for the query parameter that is a subparameter of explore. A query under explore uses the same time zone used by the explore.

Getting query LookML from an Explore

As a shortcut, Looker developers can borrow the functionality used to generate aggregate_table LookML from an Explore, then copy the aggregate table query LookML and use it as a starting point for modeled analysis LookML.

When you copy the LookML for an aggregate table, you’ll also be copying some parameters that you don’t want for your modeled query LookML. Specifically, once you copy the aggregate table LookML you will need to delete the aggregate_table and materialization parameters, since they apply only to aggregate tables. (See the aggregate_table parameter documentation page for more information about those parameters.)

Also, the aggregate table query parameter supports only a subset of the parameters that are supported by modeled Explore queries. This means that once you copy the aggregate table query LookML, you can use additional parameters for your modeled query. See the Defining a query in LookML section on this page for a full list of the parameters supported for modeled queries.

Here’s how you can use an Explore to get a base for your modeled query LookML:

  1. In your Explore, select all the fields and filters you want to include in your modeled query.
  2. Click Run to get the results.
  3. Select Get LookML from the Explore’s menu. This option is available for Looker developers only.

  1. Click on the Aggregate Table tab.
  2. Looker provides the LookML for an Explore refinement for an aggregate table. We can use the aggregate table’s query LookML and modify that for a modeled Explore query. Copy the LookML and paste it into the associated model file, which is indicated in the comment above the Explore refinement. If the Explore is defined in a separate Explore file, and not in a model file, you can add the refinement to the Explore’s file instead of the model file.

From here, you can modify the aggregate table LookML to use for a modeled query:

  1. Keep only the query parameter and its subparameters. Delete the aggregate_table and materialization parameters, since they apply only to aggregate tables.
  2. Add a name for the query. As shown in the Example section on this page, the syntax is:
    query: query_name
  3. Optionally, fill in any additional parameters for your modeled query. See the Defining a query in LookML section on this page for a full list of parameters supported for modeled queries.

Example

The following example creates an order_count_by_month modeled query for the order_items Explore:

explore: +order_items { query: order_count_by_month { description: "Number of orders placed by month in 2019" dimensions: [orders.created_month] measures: [orders.count] filters: [orders.created_date: "2019"] } }

This analysis is then displayed in the Quick Start section in the blank Order Items Explore. Select the analysis from the Quick Start section to run the analysis in the Explore:

Once the modeled analysis runs in the Explore, you can examine the data as is, or you can use the analysis as a starting point to add other fields and measures, change the filters, create visualizations, or perform any of the other actions to explore your data in Looker. Additionally, you can click the lightning bolt icon next to the Explore name:

This launches the Quick Start pop-up, where you can select a new analysis:

Selecting a Quick Start analysis from the pop-up will run the analysis and replace the previous Explore results while retaining the existing filters. For more details regarding filter behavior with Quick Start analyses, see the Quick Start filter behavior section on the Exploring data in Looker documentation page.

Top