Filtering and Limiting Data

On this Page
Docs Menu

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

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:

  • Basic Filters - Most of the time you'll use this type of filter. In these cases Looker provides appropriate dropdown lists, calendar widgets, and/or text fields you can use to put in your restriction.

  • Advanced Matches - Sometimes you'll want to specify a filter with a more advanced condition for a field, like intricate text searches, or a date range that starts in the past and goes for a certain number of days. You can often achieve your goal with this type of filter.

  • Custom Filters - When you need to specify more detailed business logic - especially when you need to combine AND and OR logic together, or want to use Looker functions - you can use custom 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.

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.

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

  • Your Looker admin can configure user attributes which specify user-specific values. For example, the admin can define a user attribute for sales region and then assign the appropriate values for individual users or groups of users.
  • Then, these user attributes can let you automatically customize a Look for each user that views it. For example, you might filter a sales region dimension to equal a sales region user attribute, then the Look filters for the user's specific sales region. Thus the Look automatically adjusts to show each user the data for their own sales region.

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 prompts you with functions, operators and field names that you might want to use in your expression. When finished, your expression must evaluate to true or false.

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:

  • Click the X to the right of the expression to completely delete it.
  • Deselect the Custom Filter checkbox to stop using the expression. As long as you do not close the page Looker will remember what you have typed, and your expression will re-appear if you click Custom Filter again.

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.

Conclusion

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.

Still have questions?
Go to Discourse - or - Email Support
Top