Question

Is conditional filtering possible?

  • 5 May 2017
  • 1 reply
  • 981 views

In LookML is it possible to apply conditional/case if… then logic to be applied ONLY if the user applies a specific filter to another dimension at run-time? Here’s an example scenario: We have a View that represents our time dimension table (not just a time dimension added to a view, but we have an entire view devoted to time). The desired user experience is to have a dimension field called Calendar Type where the user can filter between one of two values Actual and Fiscal. Once the user applies/changes this filter then we wish to have some script run that makes it so some of the dimensions in the view become visible and other dimensions become hidden. From reviewing the LookML documentation, it doesn’t appear these sort of conditional filters are possible but I am turning to community to confirm.


Thanks!


P.S. I am aware fiscal_month_offset feature in Looker, we’ve already exhaustively looked into this and our calendar needs are beyond the default feature set currently available. I am using the Actual and Fiscal field values just as an example, there are a few places we may wish to apply the design paradigm of firing off a triggered event when the end user applies a filter and handling that with some script to change the conditioning logic behind certain dimensions. So please answer regarding the problem in higher abstract not to the specific context of date time, calendars, etc…


1 reply

I accomplished this through Looker Templated Filters


Step 1.

I defined a new filter with two static values (Actual, Fiscal)


Inside my View:


filter: calendar_view_type {

label: “Calendar View Type”

default_value: “Actual”

type: string

suggestions: [“Actual”, “Fiscal”]

}


Step 2.

Then to select which field to use as source for the dimension, I used the calendar_view_type value in a CASE looking for match on my static values.


dimension:  cal_period {
type: string
sql:
CASE
WHEN {% condition calendar_view_type %} "Actual" {% endcondition %}
THEN ${TABLE}.actual_period
ELSE ${TABLE}.fiscal_period
END;;
}

Reference doc on templated filters:


Reply