Question

Conditionally_filter: Derive filter value from DB

  • 1 July 2019
  • 1 reply
  • 141 views

I was trying out conditional_filter to add a default filter and a couple of other filters that would override the default filter in case picked by the user. From the documentation it appears there is a definite set of filter expressions that can be applied to the conditional_filter. The problem here is, I need the value for the default filter to be set dynamically based on a field from a table in DB.

Is it possible to add sql to conditional_filter for this use case? If not, is there an alternate solution that caters to this use case?


1 reply

Userlevel 7
Badge +1

The first thing my brain jumps to would be replicating the conditional logic that’s conveniently created for you by the conditionally_filter, in a sql_always_where parameter.


You’d have to spell it out yourself, with


{% if view.field._is_filtered OR view.other_field._is_filtered %}
1=1
{% else %}
default filter logic, you can reference anything dynamic in the SQL here.
{% endif %}

Which says pretty much the same thing as


  conditionally_filter: {
filters: {
field: field_name
value: "Looker filter expression"
}
unless: [field, other_field, …]
}

You may have to test and play around a bit to get it to match up perfectly, but sql_always_where gives you a bit more flexibility.

Reply