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
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 the Understanding Other Project Files documentation page. For information on accessing a project’s files, see the Accessing and Editing Project Information 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 the How a Project Works in Looker 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.

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.

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 inventory_items in the model file, along with its joined views. This LookML definition causes Inventory Items to appear in the Explore menu, and joins data from inventory_items to products and distribution_centers.

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 Looker developer in Development Mode can create a blank model file in the following ways:

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. But there are many ways a Looker developer in Development Mode can add view files to a LookML project:

To use a new view, add it to your model file using the explore parameter, or use the join parameter to 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, or you can click a folder’s menu to create the file inside the folder.

  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.

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