Can I pass the filter value to the sql parameter of the filter itself?

done
low_priority
reply

#1
filter: division_filter {
    type: string
    allowed_value: {value:"West"}
    allowed_value: {value:"East"}
    allowed_value: {value:"Midwest"}
    sql:
        {% if value == "'West'" %}
          ${state} in ('California', 'Washington')
        {% elsif value == "'East'" %}
          ${state} in ('New York', 'Boston')
        {% elsif value == "'Midwest'" %}
          ${state} in ('Colorado')
        {% endif %}
    ;;
}

Would this filter work?


(Izzy) #2

You can’t have a sql: parameter inside of a filter— You make filters affect SQL by using templated filters or parameters: https://docs.looker.com/data-modeling/learning-lookml/templated-filters. That doc should have some solid examples— Note that you can also reference those values + conditions in a sql_always_where parameter of an explore, if you don’t want to use a derived table.