How to Group in Looker

Cody Schneider8 min read

Trying to make sense of a chart with dozens of categories is a common frustration in data analysis. When your traffic source report lists every single website referral individually or a sales chart breaks down revenue by all 50 states, the main insight gets lost in the noise. This is where grouping comes in - it lets you combine related values into larger, more meaningful categories, turning a cluttered visualization into a clear story.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

This tutorial will walk you through the two primary methods for grouping data in Looker. We'll cover the quick-and-dirty approach using table calculations for one-off analyses and the more robust, scalable method using LookML for creating permanent, reusable groups.

Why Group Data in Looker in the First Place?

Before jumping into the "how," it's helpful to understand the "why." Grouping isn’t just about making things look tidier, it's a fundamental analysis technique that helps you:

  • Improve Readability: A bar chart with 5 categories is far easier to understand than one with 50. Grouping cleans up your reports, allowing stakeholders to grasp the key takeaways in seconds.
  • Analyze at a Higher Level: You might not care about the performance of every single city, but you definitely care about performance by major regions (e.g., West, Midwest, South, Northeast). Grouping allows you to zoom out and see the bigger picture.
  • Simplify Complex Data: If you have dozens of marketing campaign names with different naming conventions (e.g., "FB_retargeting_q4", "fb-brand-awareness-2023"), you can group them all under a single "Facebook Ads" category for clean, high-level reporting.
  • Create Custom Segments: You can create unique, business-specific segments that don’t exist in your raw data, such as grouping customers into tiers like "High-Value," "Medium-Value," and "Casual" based on their lifetime spend.

Method 1: Using Table Calculations for Ad-Hoc Grouping

Table calculations are the fastest way to group data directly within Looker Explore. They don’t require developer access or any changes to your underlying data model (LookML). This makes them perfect for quick tests, one-off reports, and exploratory analysis.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

When to Use This Method

This is your go-to method when:

  • You don't have LookML developer permissions.
  • You're exploring a dataset and want to see if a particular grouping reveals any interesting trends before making it a permanent part of your data model.
  • You need an answer for a single report and don't anticipate needing the same grouping logic elsewhere.

Step-by-Step Guide with the if() function

Let's use a common example: grouping US states into larger sales regions. Imagine your explore has a "State" dimension and a "Total Sales" measure.

  1. Run your report: In your Explore, select the "State" dimension and the "Total Sales" measure and hit 'Run'. You’ll see a long list of every state and its corresponding sales.
  2. Add a Custom Field: Click the "Add" button next to "Custom Fields" on the data bar. This will open the custom field editor.
  3. Write your formula with nested if() statements:

The most straightforward way to group is using the if() function. The logic is: if(condition, value_if_true, value_if_false). To handle multiple groups, you'll nest if() statements inside each other.

In the "Formula" box, you would write something like this:

if( (${users.state} = "California" OR ${users.state} = "Oregon" OR ${users.state} = "Washington"), "West Coast", if( (${users.state} = "New York" OR ${users.state} = "New Jersey" OR ${users.state} = "Massachusetts"), "East Coast", if( (${users.state} = "Texas" OR ${users.state} = "Arizona" OR ${users.state} = "Oklahoma"), "South", "Other" )))

Breaking Down the Formula:

  • ${users.state} refers to the values in the "State" dimension from the "Users" view. Your field name might be different.
  • The first if() checks if the state is California, Oregon, or Washington. If so, it returns the string "West Coast".
  • If not, it moves to the next nested if(), which checks for the "East Coast" states.
  • This continues until the final "Other" value, which acts as a catch-all for any states not specifically mentioned.
  • Friendly tip: Pay close attention to your parentheses! Ensuring you have the correct number of closing parentheses at the end is the most common source of errors.
  1. Format and Name Your Field: Give your new calculation a clear name, like "Sales Region." Select "String" as the format to ensure it's treated as a text category.
  2. Save and Visualize: Click 'Save'. Your new "Sales Region" column will appear in the data table. Now, you can remove the original "State" field and create a much cleaner visualization using your new custom group.

Method 2: Creating Reusable Groups with LookML

While table calculations are convenient, they have drawbacks. They only exist in your specific report, have to be rebuilt by others who want the same logic, and can sometimes slow down performance. For frequently used groups, the better solution is to define them in LookML, Looker's data modeling language.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

When to Use This Method

This is the best approach when:

  • You have LookML developer permissions.
  • The grouping is part of your core business logic (e.g., a "Sales Funnel Stage" or "Customer Tier").
  • You want the group to be available to all users across all Explores, ensuring consistency.
  • You need the absolute best performance for large datasets.

Step-by-Step Guide Using a case Parameter

The case parameter in LookML is designed for this exact purpose. It’s cleaner and more readable than nested if() statements. For this example, let's group marketing traffic_source values into broader channels like "Paid Search," "Organic Social," "Direct," etc.

  1. Navigate to your LookML Project and View File: You’ll need to go into development mode. Find the view file that contains the dimension you want to group (e.g., sessions.view.lkml).
  2. Create a New Dimension: Add a new dimension to the file. It’s best to name it something clear, like traffic_channel.
  3. Define the Logic with case: Instead of a sql parameter, you'll use the case parameter. The structure is much more organized.
dimension: traffic_channel {
  type: string
  case: {
    when: {
      sql: ${traffic_source} = 'google' AND ${medium} = 'cpc' ,,
      label: "Paid Search"
    }
    when: {
      sql: ${traffic_source} = 'google' AND ${medium} = 'organic' ,,
      label: "Organic Search"
    }
    when: {
      sql: CONTAINS(${traffic_source}, 'facebook')  ,,
      label: "Social"
    }
    when: {
      sql: ${traffic_source} = 'direct' ,,
      label: "Direct"
    }
    else: "Other"
  }
}

Breaking Down the Code:

  • dimension: traffic_channel declares a new dimension.
  • case: { ... } is the container for all your grouping conditions.
  • when: { ... } defines a single condition. You write the condition in the sql parameter and provide the group name in the label parameter.
  • You can use more complex SQL logic here, like CONTAINS() or LIKE, to match patterns.
  • else: "Other" is the default value if none of the when conditions are met. It’s an essential best practice to prevent null values.
  1. Save and Push to Production: Save your changes in the LookML file, validate your code, commit the changes, and deploy them to production.

Once deployed, your new "Traffic Channel" dimension will appear in the Explore field picker for all users, ready to be used like any other dimension.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Table Calculations vs. LookML: Which Should You Use?

Choosing the right method comes down to a trade-off between convenience and scalability.

Use Table Calculations When...

  • You need speed and flexibility. It's the fastest way to test an idea without waiting for a developer.
  • It's a one-and-done analysis. The report is for you or a small group and won't be a staple dashboard.
  • Don't use it if... the grouping logic is complex, the report is slow, or other team members will need to create the exact same grouping.

Use LookML case When...

  • You need consistency and reliability. This is the "single source of truth" for business logic.
  • The group will be used frequently. It makes the metric available to everyone instantly.
  • Performance is a priority. The grouping logic is handled directly in the database, which is almost always faster.
  • Don't use it if... you're just quickly testing an idea or you don't have access to LookML.

Final Thoughts

Grouping data is an essential skill for cleaning up your reports and uncovering higher-level insights in Looker. For temporary or exploratory work, table calculations offer a quick method without developer overhead. For anything that represents core business logic and needs to be standardized, defining it once in LookML is the more powerful and scalable path.

While mastering these techniques in Looker is valuable, we know the process of writing custom code or nested formulas can still be a bottleneck for teams that just want fast answers. At Graphed, we created a way to handle this data analysis work using simple, natural language instead. Rather than finding the right field and writing a LookML case statement, you can connect your data sources and just ask your questions in plain English - like "group my sales by region" or "show me a bar chart of traffic channels for last month" - and get a live, interactive visualization in seconds, no Looker expressions required.

Related Articles