Look showing values only when the filter has a value

Here I share something that could be useful for some customers.

Usually, when we apply a filter without values, works as the filter is not applied at all, querying all the values. But if we want to avoid querying all the data when the filter is blank, we can reach to this approach.

Imagine we want to filter by id, we are going to create a parameter of type string, regardless of whether it is a number or not. This parameter will work as our filter. 

In this case, to populate the suggestions, I created another view querying the same Id but defining the type as string.

In order to work with this parameter as a reference, we cast the parameter as a dimension using liquid syntax as shown below with param_id_filter_toString.

order items view.png

Then, we go to model and under the explore where we're working with,  we add a sql_always_where, referencing the new dimension we created: param_id_filter_toString, matching with the id we want to filter, in this case, order_items.id

model - explore order_items.png

This will force a filter check that the id always match with the parameter the user selects. And the magic here is when we left this parameter without values, the param_id_filter_toString will have an empty string.

explore working.png

The cons are that the only condition available will be "is equals to", since we're working with a parameter instead a filter.

 

Let me know if you have other approaches to reach a similar behavior. 

 

Best for all 🙂

Solved Solved
6 3 2,018
1 ACCEPTED SOLUTION

Your approach has been most helpful — thank you! 👾

View solution in original post

3 REPLIES 3

This seems quite useful! Thanks.

Such a great tip! Thank you!!

Your approach has been most helpful — thank you! 👾

Top Labels in this Space
Top Solution Authors