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, clients, locations, or anything else that is part of your data. Any field 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 Transaction Date to just the last 90 days, even though your query only shows Payer Name and Total Net Paid Amount.
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 drop-down lists, calendar widgets, and 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.
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.
When you filter on a time dimension and try to select a range, Looker uses "until (before)" so it won't include the later date. For example, if you want to filter on Transaction Date in the range of 5/1/2019 to 5/31/2019, you need to select "is in a range" "2019-05-01" until (before) "2019-06-01".
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.
If you would like to filter on a large set of values, you can paste a long list of values into the filter field. However, the maximum number of values you can paste may be limited by your browser or other elements along your network, and may be as small as 2,000.
Adapt Filters to Each User with User Attributes
One of the basic filter options, matches a user attribute, provides user-specific flexibility. Pike13 admin can configure user attributes which specify user-specific values. However, you shouldn't need to use this.
Advanced Matches Filters
Adding an advanced matches filter starts the same way as a basic filter:
Next, select matches (advanced) from the drop-down 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.
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 drop-down 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 Ctrl+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 query results. The Creating Looker Expressions page explains how to use Looker expressions in custom fields 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 reappear if you click Custom Filter again.
The 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 the Total Net Paid amount you collected each day, you could create an Explore that looks like this:
Then you decide you only want to include the transactions over $50, so you add a filter on the Net Paid dimension:
You will still see results for each day, but the Total Net Paid amount is smaller. All of the transactions that are less than $50 are removed from the data, and what remains is summed 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, add a filter on the Total Net Paid measure to see only the days where you had more than $3,000. You get these results:
All of the transactions are summed for each day and then the filter is applied. The filter removes the days with $3,000 or less Total Net Paid amount, leaving the remaining days with more than $3,000.
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 5,000 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 five states by number of orders sold, make sure you’re sorting by orders.
If you’ve added a pivot to your report, you can also apply a column limit of up to 200. 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.
Now that you know how to limit your results to the data you’re interested in, learn how to create visualizations and charts.