Using Case statements in Filter in Looker Views

I am adding CASE statements to my filter in my views. I basically want that if the user types `Harry` the filtering should happen on `Gryffindor`. This is my code:

filter: house {
    # type: string
    # sql: ${TABLE}.house ;;
    sql:  CASE
            WHEN ${TABLE}.house LIKE '%harry%' THEN ${TABLE}.house = 'gryffindor'
            WHEN ${TABLE}.house LIKE '%luna%' THEN ${TABLE}.house = 'ravenclaw'
            WHEN ${TABLE}.house LIKE '%ernie%' THEN ${TABLE}.house = 'hufflepuff'
            WHEN ${TABLE}.house LIKE '%draco%' THEN ${TABLE}.house = 'slytherin'
          ELSE ${TABLE}.house = ${TABLE}.house END ;;
  }

When I go to explore and type out `harry` in my filter, it is returning all the values like:

gryffindor
ravenclaw
hufflepuff
slytherin
other

This is what my SQL code is looking like:

SELECT
    "house" AS "hogwarts.house"
FROM
    "schools"."hogwarts" AS "hogwarts"
WHERE (CASE
            WHEN hogwarts.house LIKE '%harry%' THEN hogwarts.house = 'gryffindor'
            WHEN hogwarts.house LIKE '%luna%' THEN hogwarts.house = 'ravenclaw'
            WHEN hogwarts.house LIKE '%ernie%' THEN hogwarts.house = 'hufflepuff'
            WHEN hogwarts.house LIKE '%draco%' THEN hogwarts.house = 'slytherin'
            ELSE hogwarts.house = hogwarts.house END )
GROUP BY
    1
ORDER BY
    1
LIMIT 500

This query will obviously return all the values. 

Is there a way that in the filter if I enter `harry` it only return:
gryffindor

1 1 2,072
1 REPLY 1
Top Labels in this Space
Top Solution Authors