I am trying to create a dynamic filter to use in a dashboard. Ideally when the user selects a value from the Filter Selector filter the values in the Dynamic Filter filter would change accordingly. For example, if the value "Age" is selected from the Filter Selector filter the value in the Dynamic Filter filter would be 10,20,30 etc, similarly when another value is selected in the Filter Selector filter the values in the Dynamic Filter filter should change accordingly. Below is my LookML,
parameter: filter_selector {
type: string
default_value: "Age"
allowed_value: {
label: "Applicant Age"
value: "Age"
}
allowed_value: {
label: "Applicant Sex"
value: "Sex"
}
allowed_value: {
label: "Applicant Race"
value: "Race"
}
}
dimension: dynamic_filter {
label_from_parameter: filter_selector
sql:
{% if filter_selector._parameter_value == "Age" %} ${Age}
{% elsif filter_selector._parameter_value == "Sex" %} ${Sex}
{% else %} ${Race}
{% endif %};;
}
When I select the "Age" value in the Filter Selector filter I am seeing the values for "Race" in the Dynamic Filter filter instead of the values for "Age" . The appropriate values (based on the value selected in Filter Selector filter) are not showing up in the Dynamic Filter.
No sure where I am messing up things in my LookML code. Can someone please help?
Solved! Go to Solution.
Hi JVFrancis,
First you'll need to make a slight change to how you're utilizing the parameter in your dynamic dimension - modify it to use this syntax for referencing the parameter values:
parameter: dimension_selector {
type: unquoted
default_value: "Age"
allowed_value: {
label: "Age"
value: "age"
}
allowed_value: {
label: "Gender"
value: "gender"
}
}
dimension: dynamic_dimension {
type: string
sql: {% if dimension_selector._parameter_value == "age" %} ${age_tier}
{% elsif dimension_selector._parameter_value == "gender" %} ${gender}
{% else %} ${age_tier}
{% endif %} ;;
}
In order to use these fields - you'll want to set your dashboard up like this:
You'll also need to modify your parameter filter in the dashboard to "Select filters to update when the filter changes" so that the suggestions reload when you change the parameter value:
Last note is that you'll need to make sure that "Age" is a string so that suggestions are actually shown in the filter - number type dimensions will not have suggestions.