User Guide Getting Started Help Center Documentation Community Training
New LookML
Old LookML
New LookML
Looker
  
English
Français
Deutsch
日本語
Understanding Model and View Files

This page provides an overview of model and view files, which are key components of most Looker projects. The other types of project files are described on this documentation page. For information on accessing a project’s files, see this documentation page.

Model Files

A model file specifies a database connection and the set of Explores that use that connection. A model file also defines the Explores themselves and their relationships to other views.

An Explore is a starting place for querying your data. In SQL terms, an Explore is the FROM clause of a query. The Explores you define in the model are seen by your users when they look at Looker’s Explore menu. (See this documentation page for more information on Explores.)

In other words, the model file is where you define which data tables should be used (as included views) and how they should be joined together, if necessary.

You typically define your Explore in a model file. However, if you have defined a native derived table (NDT), then you should define an Explore in an Explore file (explore_filename.explore.lkml).

Structure and General Syntax

Within an Explore’s curly braces, { }, you define parameters for the Explore. You can use join parameters to join other views to an Explore in a model file.

Above we see the explore called order_items in the model file, along with its joined views. This LookML definition causes Order Items to appear in the Explore menu, and joins data from order_items to order_facts and inventory_items.

For more specific information on the LookML structures in a model file, see the LookML Terms and Concepts documentation page.

Creating Model Files

Most LookML developers start with one or more model files created by generating from a set of tables in a database.

Alternatively, a blank model file can be created in Development Mode:

  1. Click + at the top of the project file list in the Looker IDE.
  2. Click Create Model.
  3. Enter a name for the model file.
    Looker supports the use of uppercase and lowercase characters, numbers, underscores, and Unicode characters in file names. If the name of your model file includes characters that are not supported by Looker, those characters will be replaced with underscores.
  4. Click Create.

You can also add a file with the extension .model.lkml to your project by dragging the file from your computer into the Looker IDE.

You can modify any model file by adding or removing Explores, specifying joins, and adding other functionality.

If you need to rename a model or any object in the model, do not rename the file or the object itself. Instead, use the label or alias parameter to change the displayed name of the file or object. The label and alias parameters change the displayed name while preserving the underlying URL used for emails or other systems.

In general, you should take precautions to make model changes as noninvasive as possible. If you do need to rename a model or an object, use the Content Validator to update all references to the model or object.

If you delete a model file, the model is not removed from any model sets to which the model belonged. If a new model file is created with the same name as a deleted model, the new model is included in any model sets that included the deleted model. This can result in giving unwanted access to the new model file. Looker admins can edit model sets and remove a deleted model to prevent this issue.

Learning More about Parameters in Model Files

Read the Model Reference, Explore Reference, and Join Reference to learn more about LookML parameters in the model file.

View Files

A view file generally defines a single “view” within Looker. A view corresponds to either a single table in your database or a single derived table.

The view file specifies a table to query and the fields (dimensions and measures) to include from that table.

Structure and General Syntax

Within each view’s curly braces, { }, are field definitions, which usually correspond to a column in the underlying table or a calculation in Looker. Looker categorizes most of them as either dimensions or measures.

Above we see the dimension id defined as a field in the Order Items view. This definition exposes the ID field for queries in the Order Items Explore.

You can also create several time-based dimensions at once using dimension groups or specify a filter for your users with filter fields. Check out the View Reference to learn more about LookML parameters in view files.

For more specific information on the LookML structures in a view file, see the LookML Terms and Concepts documentation page.

Dimensions

Fields in Looker are split into dimensions and measures. A dimension can be one of two things:

dimension: first_name { sql: ${TABLE}.first_name ;; }

dimension: full_name { sql: CONCAT(${first_name}, ' ', ${last_name}) ;; }

In Looker, dimensions always appear in the GROUP BY clause of the SQL that Looker generates.

In LookML, you can define different dimension types that correspond to different data types or formatting.

Measures

A measure computes values across multiple rows. This is equivalent to SQL aggregate functions like COUNT(), SUM(), AVG(), MIN() and MAX(). Measures can also perform simple transformations on other measures. Check out our measure types documentation to learn more.

Above we can see dimensions and measures defined in the products view file.

Creating View Files

Most LookML developers start with one or more view files created by generating from a set of tables in a database.

Alternatively, a new view file can be created:

You can also add a file with the extension .view.lkml to your project by dragging the file from your computer into the Looker IDE.

To use a new view, add it to your model file as an Explore or join it to an existing Explore in your model file.

Adding a New View from an Existing Database Table

You can create a view file from an existing database table while in Development Mode.

  1. Within a project, click + at the top of the project file list in the Looker IDE.

  2. Click Create View From Table.

  3. Looker displays a list of tables associated with one of your connections. To change the connection, use the Connection drop-down in the upper left.

  4. Select any tables that you would like to create views from by checking the box to the left of the table name. You can collapse and expand databases or schemas in this list to access all available tables.

  5. Scroll to the bottom of the page and click Create Views.

  6. Looker generates views containing LookML for all the table columns.

Adding a New View for a Derived Table

You can autogenerate or manually add a view that is based on a derived table.

Autogenerating a View for a Derived Table

To autogenerate a view that is based on a derived table:

  1. Navigate to SQL Runner.

  2. Enter the SQL statement that you would like to turn into a derived table.

  3. Click on the gear menu to the right of Run in the upper left-hand corner of the page and select Get Derived Table LookML.

  4. Copy the LookML that has been generated. Alternatively, click add it to your project, choose the project you would like to add the derived table to, and enter a name for the view in View Name.

  5. If you did not add the derived table to your project by clicking add it to your project, open your project and click + at the top of the project file list in the Looker IDE.

  6. Choose Create View.

  7. Looker displays an empty box at the top of your list of views. Type the name of the new view and press Return. Looker supports the use of uppercase and lowercase characters, numbers, underscores, and Unicode characters in file names. If the name of your view file includes characters that are not supported by Looker, those characters will be replaced with underscores.

  8. Looker opens the new view.

  9. Delete all the contents of the new view and paste the derived table LookML you copied previously.

Manually Adding a View for a Derived Table

  1. Within your project, click + at the top of the project file list in the Looker IDE.

  2. Choose Create View.

  3. Looker displays a Create File pop-up. Type the name of the new view and click Create. Looker supports the use of uppercase and lowercase characters, numbers, underscores, and Unicode characters in file names. If the name of your view file includes characters that are not supported by Looker, those characters will be replaced with underscores.

  4. Looker opens the new view.

  5. For the text that is commented out, delete irrelevant rows and remove the # characters at the beginning of each line you wish to keep.

  6. Create your derived table.

Adding a Blank View File

  1. Within your project, click + at the top of the project file list in the Looker IDE.

  2. Choose Create View.

  3. Looker displays a Create File pop-up. Type the name of the new view and click Create. Looker supports the use of uppercase and lowercase characters, numbers, underscores, and Unicode characters in file names. If the name of your view file includes characters that are not supported by Looker, those characters will be replaced with underscores.

  4. Looker opens the new view.

  5. Modify the view as needed.

Learning More about Parameters in View Files

You can learn more about view parameters in the View Parameters Reference.

Read more about LookML parameters for dimensions, measures, dimension groups, and filter fields in the Field Parameters Reference.

Top