conditionally_filter

LookML
Version

On this Page
Docs Menu

Go to Explore Parameter List

Usage

conditionally_filter is a child of
explore
explore: view_name
...
conditionally_filter:
field_name: 'default_value'
 the name of an existing field                a looker filter expression
1st
Tab
2nd
Tab
unless: [field_name]
one or more field or set names

Definition

conditionally_filter enables you to define a set of default filters, which users can override if they apply at least one filter from a second list that you define.

The conditionally_filter parameter is typically used to prevent users from accidentally creating very large queries that may be too expensive to run on your database. For example, you might force a user to limit their query to the previous week, unless they’ve explicitly asked for a larger date range.

Filters that are applied in conditionally_filter appear to the user after they have run their query. While users can change the default value that you set, they cannot completely remove the filter unless they apply at least one of the filters you specify in the unless parameter.

The field names you use can be the name of a dimension or measure.

If you need to reference a dimension or measure that is part of a joined view, rather than the explore, use view_name.field_name. Consider the following example:

- explore: order conditionally_filter: id: '123' customer.id: '678,789' unless: [date] joins: - join: customer sql_on: ${order.customer_id} = ${customer.id}

In this case the id filter refers to the id field from order. The customer.id filter refers to the id field from customer. Both filters will be applied unless the user sets an order date. This example also demonstrates that multiple filters are allowed.

The default value that you specify can accept these types of expressions.

Examples

Force the user to use an Order ID filter (with a default value of “123” that they can change) unless they apply an Order Date filter:

- explore: order conditionally_filter: id: '123' unless: [date]

Force the user to use an Order ID filter (with a default value of “123” or “234” that they can change) unless they apply an Order Date or Order Time filter:

- explore: order conditionally_filter: id: '123,234' unless: [date, time]

Force the user to use an Order ID filter (default value of “123”) and a Customer City filter (with default of “Chicago”), unless they apply an Order Date or Customer Date filter:

- explore: order conditionally_filter: id: '123' customer.city: 'Chicago' unless: [date, customer.date] joins: - join: customer sql_on: ${order.customer_id} = ${customer.id}

Common Challenges

A User Cannot Remove Every Filter When conditionally_filter Is Used

There is no way to run a query without any filters when conditionally_filter is used. One way or another a user must use the conditional filters you specify, or their own filters from the unless list.

Things to Know

There Is A Method To Apply conditionally_filter To A Subset Of Users

If you want to apply a conditional filter for some users, but not others, you can do so using model permissioning. You would need to create two models: one in which conditionally_filter is used, and one without. You can then grant access to the proper models on a user-specific basis.

If You Want To Use conditionally_filter Without unless Just Use always_filter Instead

If you want to force users to use a specific set of filters no matter what, but let them change the default value, use always_filter instead.

If You Want Filters That Cannot Be Changed At All Consider sql_always_where

If you want an explore to have filters that are the same for everyone, and not let the users change the filter value, use sql_always_where.

If You Want User-Specific Filters That Can’t Be Changed Consider access_filter_fields

If you want an explore to have filters that are specific to each user, but cannot be removed or changed, use access_filter_fields.

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