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

New in Looker 6.16, the Looker IDE supports folders to help you organize your LookML project files. See this documentation page for information.

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

Model files define Explores 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.

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). Explore files are listed in the Other category in the IDE.

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 inventory_items and user.

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 + next to Add.
  2. Click Create Model.
  3. Name the model file and press return.

Looker supports the use of uppercase and lowercase characters, numbers, underscores, and Unicode characters in filenames. If the name of your model file includes characters that are not supported by Looker, those characters will be replaced with underscores.

You can also drag a file with the extension .model.lkml into the LookML IDE, which adds the file into the Models section.

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.

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.

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.

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 drag a file with the extension .view.lkml into the LookML IDE, which adds the file into the Views section. 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 + to the right of Add in the left panel.

  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, click + to the right of Add in the left sidebar of your project.

  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 filenames. 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. In the left sidebar of your project, click + to the right of Add.

  2. Choose Create View.

  3. 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 filenames. 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 + to the right of Add in the left sidebar.

  2. Choose Create View.

  3. 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 filenames. 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