sql_case enables you to bucket results with case logic. While you can write raw SQL
CASE statements instead, there are some advantages in the Looker UI to using
sql_case. You use
sql_case by writing a value, and then assigning a SQL condition that evaluates to true or false. The conditions are evaluated in order, and the dimension returns the value of the first true condition.
If none of the conditions are true, you can use the syntax
else: name_of_overflow_bucket to name the overflow bucket. Alternatively, you can simply write your condition as
true so that the last condition is always triggered. For example:
Please note that the the suggestions presented to a user for a
sql_casedimension will not be restricted when using
full_suggestions. Any option that you include in a
sql_caseparameter will be visible to all users.
sql_case values appear in the order you write them. If you prefer an alphabetical sort, you can use
alpha_sort: true like this: