I have a dashboard that utilizes filter-only date dimensions to compare two ranges (base
and comparison
). I also have a more general global date filter which, for my dashboard use case, is redundant. I would like to have the global date filter use the filter-only dimensions in a dashboard.
The filters included are as follows:
event_date
- a date dimension implemented as a filter on the dashboard (which I would like to remove)- base range date filter (
dt_a
) - a filter applied to measures used for comparison - comparison range date filter (
dt_b
) - a filter applied to measures compared to base measures
The dimensions and filters are defined as follows:
# Global calendar date
dimension: event_date {
sql: ${TABLE}.event_date ;;
}
# Filters and filter-only dimensions
filter: dt_a {
label: "Date filter (base)"
type: date
}
dimension: group_a_yesno {
hidden: yes
type: yesno
sql: {% condition dt_a %} timestamp(${event_date}) {% endcondition %} ;;
}
filter: dt_b {
label: "Date filter (comp)"
type: date
}
dimension: group_b_yesno {
hidden: yes
type: yesno
sql: {% condition dt_b %} timestamp(${event_date}) {% endcondition %} ;;
}
I have explored liquid parameters in the table definition as well as filter setting in the dashboard itself.
Ideally, I would like the date_filter_base
and date_filter_comp
to be read into the event_date
filter applied to the broader query where the WHERE
clause reads the filters applied to each of the measures view_count_a
and view_count_b
.
For example, comparing two count_distinct
measures whose date filters are used in as OR
:
select
COUNT(DISTINCT CASE WHEN ((( timestamp(view.event_date) ) >= (TIMESTAMP('2023-11-20 00:00:00')) AND ( timestamp(view.event_date) ) < (TIMESTAMP('2023-11-25 00:00:00')))) THEN ga4_view_bq.user_pseudo_id ELSE NULL END) AS view_count_a,
COUNT(DISTINCT CASE WHEN ((( timestamp(view.event_date) ) >= (TIMESTAMP('2023-11-27 00:00:00')) AND ( timestamp(view.event_date) ) < (TIMESTAMP('2023-12-02 00:00:00')))) THEN view.user_pseudo_id ELSE NULL END) AS view_count_b,
from ...
where
((( timestamp(view.event_date) ) >= (TIMESTAMP('2023-11-20 00:00:00')) AND ( timestamp(view.event_date) ) < (TIMESTAMP('2023-11-25 00:00:00'))) OR
((( timestamp(view.event_date) ) >= (TIMESTAMP('2023-11-27 00:00:00')) AND ( timestamp(view.event_date) ) < (TIMESTAMP('2023-12-02 00:00:00')))
;
Is there a way to implement this in LookML?
LookML is pretty flexible and you can acheive it depending on what you want. Answer lies in date type parameter of type datetime. Start with defining different parameters for base and comparison dates (Used 4 for better control)
And now you can define independent filters to be applied to
event_date
(which can be removed from dashboard or very well set to be hidden now):Which in turn can be applied to measures as follows:
When all three measures are selected in a visualization and parameters above selected as:
SQL generated as follows:
If you want to apply them everywhere consider using
always_filter
in your explore and utilize these filters accordingly.