sql_case

LookML
Version

On this Page
Docs Menu

Go to Field Parameter List

Definition

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:

- dimension: status sql_case: pending: ${TABLE}.status = 0 complete: ${TABLE}.status = 1 returned: ${TABLE}.status = 2 else: unknown # Option 1 for an "unknown" overflow bucket   - dimension: status sql_case: pending: ${TABLE}.status = 0 complete: ${TABLE}.status = 1 returned: ${TABLE}.status = 2 unknown: true # Option 2 for an "unknown" overflow bucket

Please note that the the suggestions presented to a user for a sql_case dimension will not be restricted when using full_suggestions. Any option that you include in a sql_case parameter will be visible to all users.

alpha_sort

Typically, sql_case values appear in the order you write them. If you prefer an alphabetical sort, you can use alpha_sort: true like this:

- dimension: status sql_case: pending: ${TABLE}.status = 0 complete: ${TABLE}.status = 1 returned: ${TABLE}.status = 2 unknown: true alpha_sort: true

Still have questions?
Go to Discourse - or - Email Support
Top