Looker Guide

A practical guide to Looker development

View the Project on GitHub ashrithssreddy/looker-guide

🧩 Models in Looker

1. What is a Model?

A Model in Looker is the entry point for a data project. It tells Looker:

🧠 Layman Explanation

If views are tables, and explores are joinable datasets, then the model is the blueprint for how all those views and explores are wired together.

Think of the .model.lkml file as the “routing config” for your data app.

🔁 Model → Explore → View Recap

You can have multiple .model.lkml files in a project — each defining its own explore universe.

📌 TL;DR

The model file glues together views, defines explores, sets the connection, and handles caching — it’s the brain of your Looker project.

2. Model Boilerplate

A .model.lkml file defines the explores available to users and sets up project-wide configs like DB connection, includes, and caching.

🧱 Basic Structure

connection: analytics_db
include: "*.view"
include: "*.explore.lkml"

explore: orders {
  from: orders
}

🧩 Key Components

📌 Notes

3. Includes

The include: statement lets you pull other LookML files into your model file. This is how you link your views, explores, and other config files into a model.

📂 Common Patterns

include: "*.view"
include: "*.explore.lkml"
include: "shared/sets/*.lkml"

🔧 How It Works

📌 Notes

4. Connection

The connection: parameter in the model file tells Looker which database to run queries against.

🔌 What It Points To

Example:
connection: analytics_db

This tells Looker to use the analytics_db connection for all explores in this model.

📌 Notes

5. Datagroups and PDT Triggers

Looker uses datagroups to manage caching and refresh logic for Persistent Derived Tables (PDTs).

🧠 What is a Datagroup?

A datagroup defines:

It is declared in the model file.

Example:
datagroup: hourly_refresh {
  max_cache_age: "1 hour"
}

🔁 How PDTs Use Datagroups

In a view with a PDT, reference the datagroup like this:
persist_with: datagroup_trigger: hourly_refresh

This tells Looker:

persist_for: vs trigger

Use datagroup_trigger when multiple views or PDTs need to stay in sync.

📌 Notes

6. Real-World Example

Here’s a complete .model.lkml file that includes a connection, includes, explore, and a datagroup trigger.

connection: analytics_db
include: "*.view"
include: "*.explore.lkml"

datagroup: daily_refresh {
  max_cache_age: "24 hours"
}

explore: orders {
  from: orders

  join: users {
    type: left_outer
    sql_on: ${orders.user_id} = ${users.id} ;;
    relationship: many_to_one
  }
}

This model connects to a DB, loads all views and explores, applies a 24-hour cache policy, and defines an orders explore with a users join.