Filtering and Limiting Data

Looker lets you limit the data you see based on criteria you specify. For example, you might want to filter the results to the last three months, or for a certain customer. You can also limit the number of rows displayed, or the number of pivot columns displayed. This tutorial introduces you to filtering and limiting data in Looker.

Filtering Data Overview

You can restrict the data you’re viewing to items of interest by adding filters. For example, you might limit the results to certain dates, customers, locations, or anything else that is part of your data. Any field in your Looker instance can become a filter.

You don’t necessarily need to add a dimension or measure to your results in order to filter on it. For example, you can create a query that filters the Order Date to just the last 90 days, even though your query only shows Customer and Number of Orders.

There are several different types of filters:

You can use any combination of these filter types in your query.

Basic Filters

There are several different ways to add a basic filter:

You’ll see that a filter appears in the Filters section above your results. To remove a filter, click the X to its right.

Standard Types of Filter Options

The available options for the filter depend on its type.

For example, a time dimension will have options to select a time range, while a numeric dimension will have options like “equal to” or “greater than”.

For text dimensions, Looker helps you choose filter values by displaying a list of existing data values for that field. As you type, Looker narrows the list to just those values that include that text.

Filtering That Adapts to The User Using User Attributes

One of the basic filter options, matches a user attribute, provides user-specific flexibility:

Advanced Matches Filters

Adding an advanced matches filter starts the same way as a basic filter:

Next, select matches (advanced) from the dropdown menu of your filter:

This will give you a text field to type in a filter expression. To remove the filter, click the X to its right. Clicking the help link takes you to a page listing the various filter expressions you can use.

As mentioned above, your Looker admin can configure user-specific values called user attributes that let you automatically customize a Look for each user that views it. If you want to reference a user attribute in an advanced matches filter, use the syntax {{ _user_attributes['name_of_your_attribute'] }}.

Custom Filters

Custom filters let you create filters with custom conditions that might not be available with the other, simpler filter types. These conditions can be simple or complex. You write the fields, constants, functions, and operators that express the filtering that you want.

When you add a custom filter, Looker displays an editor for you to build an expression that evaluates as true or false. When you run the query, Looker will only return rows for which that condition is true.

Adding a Custom Filter

To add a custom filter, expand the Filters section and click the Custom Filter checkbox in the upper right:

To create a Looker expression for your custom filter, start typing a dimension or function. Looker will display a list of functions, operators and field names that you might want to use in your expression. Click on a term in the dropdown to add it to your expression. When finished, your expression must evaluate to true or false.

Click Run (or use the keyboard shortcut command-enter for Mac or control-enter for Windows) to run your query with your custom filter applied.

The Creating Looker Expressions page explains how to create Looker expressions and how the editor helps you.

Looker expressions can use as many fields, functions, and operators as your business logic requires. Just keep in mind that the more complex your condition, the more work your database must do to evaluate it, which may lengthen query times.

Because custom filters are used to create a database query, you cannot refer to measures in a custom filter, or use any functions that rely on a finished result set. The Creating Looker Expressions page discusses this concept in more detail. The Looker Functions and Operators page shows you the available functions and identifies which can be used in a custom filter.

Removing a Custom Filter

To remove a custom filter, you can:

Difference Between Filtering Dimensions and Filtering Measures

Filters are applied differently to dimensions and measures.

Filtering Dimensions: Restricts Raw Data Before Calculations

When you filter on a dimension, you are restricting the raw data before any calculations are made. For example, if you want to see how many orders were placed each day for the previous seven days, you could create an Explore that looks like this:

Then you decide you only want to count orders over $50, so you add that filter:

You will still see results for each day, but the order counts are much smaller. All of the orders that are less than $50 are removed from the data, and what remains is counted by the measure for each day.

Filtering Measures: Calculates First, Then Restricts the Results

When you filter on a measure, however, you are restricting the results after the measure has been calculated. For example, start from the same Explore used in the prior section:

This time, filter your results to only see the days where you had more than 325 orders. You get these results:

All of the orders are counted for each day and then the filter is applied. The filter removes the days that had 325 or fewer orders, leaving the remaining four days that had more than 325 orders.

Limiting Data

Sometimes you only want to see a subset of the complete results from your query. You can do this in Looker by setting a row limit, column limit, or both. Looker supports a row limit of up to 5000 and recommends a column limit of 50 or less.

When you set a row limit Looker will only display up to the number of rows you have set. Looker will warn you if you might be hiding data by setting a row limit that is too low. Your sort order is important in these situations; Looker first applies the sort, and then applies the limit. For example, if you only want to see the top 5 states by number of orders sold, make sure you’re sorting by orders.

Note that if you reach a row limit you will not be able to sort row totals or table calculations.

If you’ve added a pivot to your report, you can also set a column limit. Looker will warn you if you might be hiding data by setting a column limit that is too low. Again, the sort order of your pivot is important, because Looker first applies the sort, and then applies the limit. For example, if you want to see the 5 most recent order created months, make sure you’re sorting by the order created month.


Now that you know how to limit your results to the data you’re interested in, learn how table calculations can help you with your analysis.