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
include

Usage

include: "/views/airports.view"

Hierarchy

include

- or -

include

Default Value

None

Accepts

A string containing a filename or pattern

Definition

The include parameter specifies the LookML files that will be available to a model, a view, or an Explore. If you want to use or reference a LookML file within another file, you must add it with the include parameter.

You can use the include parameter in model files, view files, and Explore files. The include parameter can reference different types of LookML files, depending on the context.

In a model file, you can use include to reference:

In a view file, you can use include to reference:

In an Explore file, you can use include to reference:

You can also use include to bring in files from other projects. See the Importing Files from Other Projects documentation page for information on including files from another project. To import files from local LookML projects, you must enable the Local Project Import Labs feature.

Note the following when using include:

Handy Tip: When using wildcards, you can check which files are included by hovering over the information icon in the change bar of the file, or by clicking on the include statement and looking in the quick help:

Using include in a Model File

You can use the include parameter in a model file to include views and dashboards or Explores.

Including Views and Dashboards in a Model

Use the include parameter in a model file to specify the dashboard and view files that will be available to that model. If you want to use or reference a LookML file within a model, you must add it with the include parameter.

In the include parameter, use the extension .view for view files and the extension .dashboard for dashboards. You can leave out the .lkml and .lookml part of these extensions.

You can use the * wildcard character to indicate files with strategic naming conventions or with the same extension. You can also use the * wildcard in combination with directory paths to specify multiple files, as described in the Wildcard Examples section of the IDE folders documentation page.

For example, you could use these include parameters in a model file:

include: "/**/*.dashboard" include: "/*/*base.view.lkml" include: "//e_commerce/views/*.view.lkml"

These parameters would include the following files:

If your project has a large number of view files or if your project uses persistent derived tables (PDTs), you should avoid including all view files in your model. Instead, include individual view files like this. Here’s an example of including individual view files and all dashboards in a project:

include: "/views/order.view" include: "/views/user.view" include: "/**/*.dashboard"

Including Models in a Model

You cannot include a model file from another project. Instead, if you want to reuse, refine, or extend Explores across projects, in the imported project you can create a separate Explore file, then include that Explore file in other projects. See Including Explores in a Model for more information.

Including Explores in a Model

Explore files will listen to the connection of the model they are included in. Consider this fact when you include Explore files in models that are configured with a connection that is different from the Explore file’s parent model. If the schema for the including model’s connection differs from the schema for the parent model’s connection, it can cause query errors.

Explores are usually defined within a model file. However, sometimes you need a separate Explore file for an NDT, or to extend or refine an Explore across models.

If you do have a separate Explore file, you need to use the include parameter in the model file to include it. In the include parameter, use the extension .explore.lkml for Explore files.

For example, below is a model file that has two Explores:

connection: "faa" include: "/explores/aircraft_new.explore.lkml" include: "/views/accidents.view" explore: accidents { view_name: accidents from: accidents }

Including Data Tests in a Model

Data tests can be defined directly in a model file or a view file. However, you can also create a separate data test file if you want to reuse your data tests in multiple places in your project.

If you do have a separate data test file, you need to use the include parameter in your model file or view file so that you can run the data tests. In the include parameter, use the extension .lkml for data test files.

For example, below is an excerpt from a model file that includes a data test file:

connection: "faa" include: "/explores/aircraft_new.explore.lkml" include: "/views/accidents.view" include: "/tests/data_tests.lkml" …

Once you include the data test file in a model file, you can run the data test to verify that your data test works properly and to see if your model’s logic passes the test.

You can also include the data test file in a view file, as described in the section of this page called Including Data Tests in a View.

Using include in a View File

For the most part, you don’t need to use include in a view file. However, there are some cases in which you do want to include files in your view file:

Including Views in a View (to Extend or Refine)

You can also include a view file in another view file to extend or to refine the included view.

For example, here is the marketing_order_fields view file that includes the basic_order_fields view file and then extends it:

include: "/views/basic_order_fields.view" view: marketing_order_fields { extends: [basic_order_fields] # The file that contains the basic_order_fields } # view should be included

Including Explores in a View

Explore files will listen to the connection of the model they are included in. Consider this fact when you include Explore files in models that are configured with a connection that is different from the Explore file’s parent model. If the schema for the including model’s connection differs from the schema for the parent model’s connection, it can cause query errors.

In most cases, you don’t need to include an Explore in a view. However, native derived tables (NDTs) are a special case because they are defined in their own view file that has an explore_source parameter. You use the explore_source parameter to specify an Explore and define the desired columns and other desired characteristics for the NDT. Explores are usually defined within a model file, but in the case of NDTs it may be cleaner to create a separate file for the Explore using the .explore.lkml file extension. If you create a separate Explore file, you must include the Explore file in the NDT view file.

Here is an example of using include in a NDT view file to point to an Explore file:

include: "/explores/order_items.explore.lkml" view: user_order_facts { derived_table: { explore_source: order_items { column: user_id {field: order_items.user_id} column: lifetime_number_of_orders {field: order_items.order_count} column: lifetime_customer_value {field: order_items.total_revenue} derived_column: average_customer_order { sql: lifetime_customer_value / lifetime_number_of_orders ;; } } } dimension: user_id {hidden: yes} dimension: lifetime_number_of_orders {type: number} dimension: lifetime_customer_value {type: number} dimension: average_customer_order {type: number} }

See our documentation on using include statements to enable referencing fields for more information on Explore files for NDTs.

Including Data Tests in a View

Data tests can be defined directly in a model file or a view file. However, you can also create a separate data test file if you want to reuse your data tests in multiple places in your project.

If you do have a separate data test file, you need to use the include parameter in your model file or view file so that you can run the data tests. In the include parameter, use the extension .lkml for data test files.

For example, below is an excerpt from a view file that includes a data test file:

include: "/tests/data_tests.lkml" view: orders { sql_table_name: looker.orders ;; dimension: id { primary_key: yes type: number sql: ${TABLE}.id ;; } …

Once you include the data test file in a view file, you can run the data test to verify that your data test works properly and to see if your view’s logic passes the test.

You can also include the data test file in a model file, as described in the section of this page called Including Data Tests in a Model.

Using include in an Explore File

Explores are usually defined within a model file. However, sometimes you need a separate Explore file for an NDT, or to extend or refine an Explore across models.

If you do have a separate Explore file, you can use the include parameter to include views or other Explores.

Including Views in an Explore

If you have a separate Explore file, you need to include any views that are used by the Explore. Use the file extension .view for view files. You can leave out the .lkml part of the file extension. Here is an example Explore file that includes the two views it’s using:

include: "/views/aircraft.view" include: "/views/aircraft_types.view" explore: aircraft { join: aircraft_types { type: left_outer sql_on: ${aircraft.aircraft_type_id} = ${aircraft_types.aircraft_type_id} ;; relationship: many_to_one } }

Including Explores in an Explore

Explore files will listen to the connection of the model they are included in. Consider this fact when you include Explore files in models that are configured with a connection that is different from the Explore file’s parent model. If the schema for the including model’s connection differs from the schema for the parent model’s connection, it can cause query errors.

You can include one Explore file in another Explore file, such as when you are extending or refining an Explore. Use the include parameter and add the file extension .explore.lkml.

Here is an example Explore file that includes another Explore file and then extends the Explore:

include: "/explores/base.explore.lkml" explore: aircraft_information { extends: [aircraft] }

Examples

See the previous sections for examples of using include in model files, view files, and Explore files.

Things to Consider

Using Wildcards

For projects where only a few files need to be managed, you can list each file in its own include parameter, like this:

include: "/dashboards/user_info.dashboard" include: "/views/users.view"

Bur for projects with many files to include, you can reduce the number of include parameters that you need to write by using wildcards to include several files at once:

Using wildcards may be especially helpful during development when you need to create a temporary fix for LookML validation warnings, especially when organizing an existing project into IDE folders. But take the following into consideration when using wildcards in your include statements:

Using Wildcards with IDE Folders

You can use wildcards in combination with IDE folders to include files in a specific directory in your LookML project.

For example, this include statement references all the files in the /explores/ directory of a LookML project:

include: "/explores/*"

Using Wildcards for Specific File Types

You can use wildcards to reference all files of a specific type. For example, this include statement references all Explore files in a LookML project:

include: "/**/*.explore.lkml"

See the Project File Types section of the LookML Project Files documentation page for a list of the types of LookML files and their file extensions.

Looker does not recommend the use of wildcards to include all view files in a project, since including all view files can affect the performance of LookML validation and can clutter your database schema.

Using Wildcards with Strategic Naming Patterns

You can also use wildcards with strategic file naming to further optimize your include statements. For example, instead of naming files like this:

/views/apple.view /views/banana.view /views/cherry.view /views/orange.view /views/celery.view

You can add a strategic prefix or suffix to your filenames, like this:

/views/apple.fruit.view /views/banana.fruit.view /views/cherry.fruit.view /views/orange.fruit.view /views/celery.vegetable.view

Then use wildcards to reference only the .fruit suffix by using this include:

include: "/views/*.fruit.view"

Including All View Files Can Affect Performance of LookML Validation

If your project has a large number of view files and you include them all in your model file, this may affect the performance of the LookML Validator. Since the LookML Validator checks all the view files included in the model, you should include only the needed view files in the model file’s include parameter. Consider using strategic naming conventions for view files to enable easy inclusion of groups of views within a model (see example here). Or, you can use IDE folders to organize your views into folders. Then you can use the * wildcard to include all views in a single folder, instead of including all views in your project. See our documentation on using include with IDE folders for information.

Including All View Files Can Clutter Your Database Schema

For projects that use persistent derived tables (PDTs), you can include the PDT’s view file in your model file. However, each model file that includes the PDT’s view file will create a copy of the PDT in the scratch schema on your database. If you have multiple model files and you include all view files in your model files, you may add unnecessary clutter to your database scratch schema. For this reason, be sure that you include a PDT’s view file only in the model files where the PDT is needed.

Top