This page refers to the
filters
parameter that is part of a measure.
filters
can also be used as part of a native derived table, described on theexplore_source
parameter documentation page.
filters
can also be used as part of a dashboard, described on the Dashboard parameters documentation page.
filters
can also be used as part of a dashboard element. A representative example of its usage is provided on the documentation page for column chart elements.
Usage
measure: field_name {
filters: [dimension_name: "filter expression", dimension_name: "filter expression", … ]
}
}
Hierarchyfilters |
Possible Field TypesMeasureAcceptsA set of dimension names and corresponding Looker filter expressions |
Definition
filters
is an optional list of filter expressions that are applied to a measure calculation. It works only with the following measure types that perform aggregation:
type: count
type: count_distinct
type: sum
type: average
The syntax for filters is:
Refer to Looker’s filter notation for details on how to write valid filter expressions. Place the entire filter expression in quotation marks, as shown in the following examples.
Examples
In this example, the measure will count distinct IDs that were created in the past seven days and were not from users with disabled accounts. This example also illustrates how to add multiple filters to a field. Each filter expression requires its own complete filters
parameter:
As another example, consider data that includes one row per person, who is either a regular employee or a contractor. There is a field, is_contractor
, of type yesno
that contains yes
if the person is a contractor. This measure will count only rows for contractors:
In this next example, the filters
expression contains multiple values. The measure will count all rows that match any of the four values in the state
field:
In this example, the filter is given a numeric value. The measure will add only orders that have a price
of more than 100:
In this example, the filter is given a range of numeric values. The measure will total orders from customers in the 18-25 age group:
Common challenges
Don’t use filters
with measures of type: number
Many users try to use filters
with measures of type: number
, which does not work:
Instead, apply a filters
parameter to any of the individual measures that make up the measure of type: number
, as follows: