<br />

> [!WARNING]
> **Preview:** This feature is subject to the "Pre-GA Offerings Terms" in the [General Service Terms](https://cloud.google.com/terms/service-terms#1) section of the Service Specific Terms. Pre-GA products and features are available "as is" and might have limited support. For more information, see the [launch stage descriptions](https://cloud.google.com/products#product-launch-stages).
>
> If you encounter an issue during the Public Preview of Looker interoperability with analytic models, report it to [database_analytic_models_feedback@google.com](mailto:database_analytic_models_feedback@google.com).

> This page refers to the `sql_analytic_model_name` parameter that is part of an [Explore](https://docs.cloud.google.com/looker/docs/reference/param-explore-explore.md.txt).
>
> `sql_analytic_model_name` can also be used as part of a view, described on the [`sql_analytic_model_name` (for views)](https://docs.cloud.google.com/looker/docs/reference/param-view-sql-analytic-model-name.md.txt) parameter documentation page.

## Usage

```
explore: explore_name {
  sql_analytic_model_name: analytic_model_name ;;
}
```

|---|---|
| Hierarchy [Model File](https://docs.cloud.google.com/looker/docs/reference/param-model.md.txt) [`explore`](https://docs.cloud.google.com/looker/docs/reference/param-explore-explore.md.txt) `sql_analytic_model_name` | Default Value None <br /> Accepts An in-database analytic model name <br /> Special Rules - Analytic models are supported only for BigQuery and Snowflake connections. - `sql_analytic_model_name` for Explores should be used only when the same view can describe multiple analytic models on your database. - The analytic model referenced by `sql_analytic_model_name` must be [accessible within the database connection of its model](https://docs.cloud.google.com/looker/docs/reference/param-explore-sql-analytic-model-name.md.txt#accessible_to_connection). - If the analytic model is in a different database, schema, project, or dataset than the default path you defined in your database connection, you must [scope](https://docs.cloud.google.com/looker/docs/reference/param-explore-sql-analytic-model-name.md.txt#fully_scoped) the analytic model name. |

## Definition

For BigQuery and Snowflake connections, the `sql_analytic_model_name` parameter specifies the name of an existing [in-database analytic model](https://docs.cloud.google.com/looker/docs/analytic-models.md.txt) (a [BigQuery Graph](https://docs.cloud.google.com/bigquery/docs/graph-overview.md.txt) or a [semantic view in Snowflake](https://docs.snowflake.com/en/user-guide/views-semantic/overview)) to use as the basis for a LookML Explore.

In most cases, you use the [`sql_analytic_model_name` (for views)](https://docs.cloud.google.com/looker/docs/reference/param-view-sql-analytic-model-name.md.txt) parameter to specify an analytic model in your view file. Then, in that view file, you define LookML dimensions and measures that are based on the analytic model in your database. However, in cases where your database has multiple analytic models that can be defined by the same LookML fields, you can use the `sql_analytic_model_name` parameter under an `explore` parameter.

When you specify a `sql_analytic_model_name` under an `explore` parameter, the Explore will override the analytic model specified in the view file and instead query the analytic model that you specified in the `sql_analytic_model_name` under the `explore` parameter. In this case, the Explore will use the LookML measures and dimensions that are defined in the view file, but apply them to the analytic model that's specified in the `sql_analytic_model_name` parameter of the `explore` parameter.

### Scoping analytic model names

When you reference an analytic model by using the analytic model name alone, Looker uses the default search path (the database and schema) that your Looker admin has configured in the settings for the database connection.

If you need to reference an analytic model in a different database and schema that isn't in the database user's default search path, you can scope the analytic model name by using the `<database_name>.<schema_name>.<analytic_model_name>` format to point to another database or schema:

- To reference an analytic model from a different schema, use `<schema_name>.<analytic_model_name>`.
- To reference an analytic model from a different database, use the full `<database_name>.<schema_name>.<analytic_model_name>`.

For a Google BigQuery connection, you can reference an analytic model in a different project and dataset by scoping the analytic model name using the format `<project_name>.<dataset_name>.<analytic_model_name>`. See the [Google BigQuery connection](https://docs.cloud.google.com/looker/docs/db-config-google-bigquery.md.txt#billing_project_id) documentation page for additional information.

## Example

Here is an example LookML view called `MyStoreGraphView` that's based on a `StoreGraph` BigQuery Graph on a BigQuery database, including dimensions and measures that are mapped to the Graph:

    view: MyStoreGraphView {
      sql_analytic_model_name: StoreGraph ;;

      dimension: location_id {
        type: number
        sql: Stores_location_id ;;
      }

      dimension: population {
        type: number
        sql: Locations_population ;;
      }

      dimension: location_name {
        type: string
        sql: Locations_name ;;
      }

      measure: locations_total_population {
        type: number
        sql: Locations_total_population ;;
      }
    }

Assuming that the database has another Graph called `ShopDetailsGraph` with the same elements as the `StoreGraph`, here is an Explore that overrides the `sql_analytic_model_name` value in the `MyStoreGraphView` view file. The Explore will have the same LookML dimensions and measures that are defined in the `MyStoreGraphView`, but the Explore will query the `ShopDetailsGraph` analytic model:

    explore: MyStoreGraphView {
      sql_analytic_model_name: ShopDetailsGraph ;;
    }

## Things to consider

### Considerations for analytic models in Looker

When using in-database analytic models, keep the following considerations and limitations in mind:

- **Data types:** Only the following data types for [dimensions](https://docs.cloud.google.com/looker/docs/reference/param-dimension-filter-parameter-types.md.txt) and [measures](https://docs.cloud.google.com/looker/docs/reference/param-measure-types.md.txt) are supported with analytic models:

  - Supported for dimensions and measures:
    - `string`
    - `number`
    - `date`
    - `yesno`
  - Supported for dimensions only:
    - `time`
    - `date_time`
- **Measures:**

  - **Base measures must be predefined:** Base measures must be predefined in the underlying database analytic model. Looker can't define a new base measure by performing an aggregation (such as [`type: sum`](https://docs.cloud.google.com/looker/docs/reference/param-measure-types.md.txt#sum) or [`type: count`](https://docs.cloud.google.com/looker/docs/reference/param-measure-types.md.txt#count)) on a dimension from an analytic model.
  - **Measures that are based on other measures are supported:** You can use the `sql` parameter of a LookML measure to perform non-aggregate computations that use predefined base measures from the analytic model. When you create a measure that's based on other measures, you can't define the new measure as an aggregate measure type such as `sum` or `count`. You must define the new measure as a non-aggregate measure type, such as [`string`](https://docs.cloud.google.com/looker/docs/reference/param-measure-types.md.txt#string), [`number`](https://docs.cloud.google.com/looker/docs/reference/param-measure-types.md.txt#number), [`date`](https://docs.cloud.google.com/looker/docs/reference/param-measure-types.md.txt#date), or [`yesno`](https://docs.cloud.google.com/looker/docs/reference/param-measure-types.md.txt#yesno). See the following example:

        measure: average_order_amount {
          type: number
          sql: ROUND(${total_order_amount} / NULLIF(${count_orders}, 0), 2) ;;
        }

- **Joins:** An Explore whose base view is based on an analytic model can't include any joins. Similarly, a view that's based on an analytic model can't be joined into an Explore that has a standard LookML base view.

- **Implicit joins:** Features that rely on implicit joins aren't supported for analytic models. Some examples of features that rely on implicit joins are [custom calendars](https://docs.cloud.google.com/looker/docs/custom-calendars.md.txt) and fields that are defined with [`type: location`](https://docs.cloud.google.com/looker/docs/reference/param-dimension-filter-parameter-types.md.txt#location), [`type: distance`](https://docs.cloud.google.com/looker/docs/reference/param-dimension-filter-parameter-types.md.txt#distance), or [`type: zipcode`](https://docs.cloud.google.com/looker/docs/reference/param-dimension-filter-parameter-types.md.txt#zipcode).

- The following features are not supported with analytic models:

  - [Filtered measures](https://docs.cloud.google.com/looker/docs/reference/param-field-filters.md.txt)
  - [Aggregate awareness](https://docs.cloud.google.com/looker/docs/aggregate_awareness.md.txt)
  - [Looker legacy runtime](https://docs.cloud.google.com/looker/docs/legacy-feature-schedule.md.txt#new_lookml_runtime)

### The analytic model must be accessible from the current connection

When the `sql_analytic_model_name` parameter is used within an [`explore`](https://docs.cloud.google.com/looker/docs/reference/param-explore-explore.md.txt) object, that `explore` object is in turn included in a [model](https://docs.cloud.google.com/looker/docs/reference/param-model.md.txt) object. (The [Hierarchy](https://docs.cloud.google.com/looker/docs/reference/param-explore-sql-analytic-model-name.md.txt#hierarchy) on this page shows this relationship chain.) The model object has a database [`connection`](https://docs.cloud.google.com/looker/docs/reference/param-model-connection.md.txt) defined in it. When you reference an analytic model in the `sql_analytic_model_name` parameter, the analytic model needs to be accessible within the associated connection specified in the model file.

The default [database](https://docs.cloud.google.com/looker/docs/connecting-to-your-db.md.txt#database) and [schema](https://docs.cloud.google.com/looker/docs/connecting-to-your-db.md.txt#schema) (or, for Google BigQuery, the [billing project](https://docs.cloud.google.com/looker/docs/db-config-google-bigquery.md.txt#billing_project_id) and [dataset](https://docs.cloud.google.com/looker/docs/db-config-google-bigquery.md.txt#dataset)) are defined by your Looker admin when they [create the Looker connection to your database](https://docs.cloud.google.com/looker/docs/connecting-to-your-db.md.txt).