Using LookML CASE

Hi Team, 

I am referring to below link to achieve my requirement.

https://help.looker.com/hc/en-us/articles/360023657833

With above link i have achieved the DropDown based on different case condition but when i use the AND operator in the LookML Case statement it is not comparing the condition and result it to the “No Result”. Below is my code for your reference. Can i achieve it with LookMl Case Statement.


 

dimension: dimension_test {
    case: {
      when: { 

        sql:${TABLE}."JSON":"Field1"::string = 'value1' ;;
        label: "Label1"
      }      
      when: {
        sql:${TABLE}."JSON":"Field1"::string = 'value2' ;;
        label: "Label2"
      }
      when: {
        sql:${TABLE}."JSON":"Field1"::string = 'value13' ;;
        label: "Label1"
      }
      when: {
        sql:${TABLE}."JSON":"Field1"::string = 'value4' AND ${view_name.Field2}='xyz';;  // Here i used the AND operator and which results "No Results". All above code working fine.
        label: "Label4"
      }

      
      

      else: "NA"
    }
  }

Please help me how can i achieve it.

0 1 1,103
1 REPLY 1

Hello kadiwalanaeem,

Are all of the specified values distinct in your use case?

If not, it is worth keeping in mind that the order of the ‘when’ parameters may change your results, as these conditions are checked in order, from first to last.

As such, the following dimension will only return the first value, as all conditions are met by the time it reaches the second ‘when’ parameter - 
 

  dimension: dimension_test {
    case: {
      when: {
        sql: ${Field1} = 'VALUE1' ;;
        label: "Label1"
      }
      when: {
                sql: ${Field1} = 'VALUE1' AND ${view.Field2} = 'VALUE2';;
        label: "Label2"
      }
      else: "NA"
    }
  }

However, the following dimension will return both values - 

  dimension: dimension_test {
    case: {
      when: {
                sql: ${Field1} = 'VALUE1' AND ${view.Field2} = 'VALUE2';;
        label: "Label2"
      }

      when: {
        sql: ${Field1} = 'VALUE1' ;;
        label: "Label1"
      }
      else: "NA"
    }
  }

Hope this helps!

Hayley

Top Labels in this Space
Top Solution Authors