User Guide Getting Started Help Center Documentation Community Training
New LookML
Old LookML
New LookML


view: view_name {
  dimension: field_name {
    case: {
      when: {
        sql: SQL condition ;;
        label: "value"
      # Possibly more when statements
      else: "value"
    alpha_sort: yes



Possible Field Types



A SQL condition and a string

Special Rules

Use an alpha_sort parameter if you want the values alphabeticalized


case enables you to bucket results with case logic. While you can write raw SQL CASE statements instead, using case will create a drop-down menu for your users in the Looker UI. A SQL CASE statement will not create such a menu.

The general form of case is:

dimension: status { case: { when: { sql: condition ;; label: "Label of Condition" } # possibly more when statements else: "Label If No Condition Met" } }

These parameters work as follows:

The suggestions presented to a business user for a case dimension will not be restricted when using full_suggestions. Any option that you include in a case parameter will be visible to all users.

Choosing the Sort Order of Labels with alpha_sort

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

dimension: status { alpha_sort: yes case: { … } }


Assign several human-readable labels to different status numbers:

dimension: status { case: { when: { sql: ${TABLE}.status = 0 ;; label: "pending" } when: { sql: ${TABLE}.status = 1 ;; label: "complete" } when: { sql: ${TABLE}.status = 2 ;; label: "returned" } else: "unknown" } }

When multiple conditions evaluate to the same label, LookML uses only the last condition. In the example below, Looker will use ${TABLE}.status = 2 instead of ${TABLE}.status = 0 to generate the SQL CASE statement that evaluates to pending.

view: orders dimension: status { case: { when: { sql: ${TABLE}.status = 0 ;; label: "pending" } when: { sql: ${TABLE}.status = 1 ;; label: "complete" } when: { sql: ${TABLE}.status = 2 ;; label: "pending" } else: "unknown" } }

The SQL query constructed from this LookML will be something like:

CASE WHEN orders.status = 1 THEN ‘complete’ WHEN orders.status = 2 THEN ‘pending’ ELSE ‘unknown’ END AS orders.lookml_case