User Guide Getting Started Help Center Documentation Community Training
New LookML
Old LookML
New LookML
  
English
日本語
case

Usage

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

Hierarchy

case

Possible Field Types

Dimension

Accepts

A SQL condition and a string

Special Rules

Use an alpha_sort parameter if you want the values alphabeticalized

Definition

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: { … } }

Examples

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" } }
Top