how to create a custom filter in lookml?

I have a single column called "field" and in that column it can be called "A" or "B" 

I want to have a single select filter radio button on looker with 3 options ("A", "B", "A & B") 

how can I create this kind of a custom filter? 

Solved Solved
0 3 1,966
1 ACCEPTED SOLUTION

First step is going to be creating a parameter that has the filter values that you'll want to appear in the radio button:

  parameter: gender_filter {
    type: unquoted
    allowed_value: {
      label: "Male"
      value: "male"
    }
    allowed_value: {
      label: "Female"
      value: "female"
    }
    allowed_value: {
      label: "Male or Female"
      value: "maleorfemale"
    }
    default_value: "Male"
  }

 Next step is to create a yesno dimension to help apply the parameter to whatever dimension you're trying to filter:

  dimension: gender_display {
    type: yesno
    sql: {% if gender_filter._parameter_value == "male" %} ${gender} = "Male"
      {% elsif gender_filter._parameter_value == "female" %} ${gender} = "Female"
      {% else %} ${gender} = "Male" or ${gender} = "Female"
      {% endif %} ;;
  }

 Then you can setup your dashboard to use these fields - use the yesno filter as your filter in the looks on your dashboard and set the value to "Yes" so that the values are filtered when users change the dashboard filter. 

Screenshot 2024-08-20 at 11.23.14 AM.png

 Configure your dashboard filter using the parameter you created with your three options: 

Screenshot 2024-08-20 at 11.23.55 AM.png

Screenshot 2024-08-20 at 11.24.13 AM.png

View solution in original post

3 REPLIES 3

Hi @BrianLewis - Could you provide a little bit more clarity on your question - I'm struggling to understand how a dimension value could be both A & B at the same time. Do you mean A OR B? 

Are we working with a dimension that's a type string? 

Maybe you can post a sample of the specific data you're trying to work with so I can help you out? 

You can create custom filters in Looker using a Filter but I'm not certain this is the right path you'll want to go down. 

Any more specifics you could provide would be super helpful! 

sorry about that..yes, that would be an OR. example below

field = 'A'

field = 'B'

field in ('A','B')

First step is going to be creating a parameter that has the filter values that you'll want to appear in the radio button:

  parameter: gender_filter {
    type: unquoted
    allowed_value: {
      label: "Male"
      value: "male"
    }
    allowed_value: {
      label: "Female"
      value: "female"
    }
    allowed_value: {
      label: "Male or Female"
      value: "maleorfemale"
    }
    default_value: "Male"
  }

 Next step is to create a yesno dimension to help apply the parameter to whatever dimension you're trying to filter:

  dimension: gender_display {
    type: yesno
    sql: {% if gender_filter._parameter_value == "male" %} ${gender} = "Male"
      {% elsif gender_filter._parameter_value == "female" %} ${gender} = "Female"
      {% else %} ${gender} = "Male" or ${gender} = "Female"
      {% endif %} ;;
  }

 Then you can setup your dashboard to use these fields - use the yesno filter as your filter in the looks on your dashboard and set the value to "Yes" so that the values are filtered when users change the dashboard filter. 

Screenshot 2024-08-20 at 11.23.14 AM.png

 Configure your dashboard filter using the parameter you created with your three options: 

Screenshot 2024-08-20 at 11.23.55 AM.png

Screenshot 2024-08-20 at 11.24.13 AM.png

Top Labels in this Space
Top Solution Authors