Creating a new column

Is there a way to create a new column based on the values of another column? In another viz tool, I could use the following --- Case [column_name] when ‘Levi’ then ‘Apple’ else [column_name] END

They were called calculated columns

Solved Solved
0 4 3,521
1 ACCEPTED SOLUTION

Hi @3piecechickendi

We would nest conditions or even use an AND or OR condition. 

7f028fc2-70aa-411b-a4b5-9b165bffd704.png

Thanks,

Eric

View solution in original post

4 REPLIES 4

Hi @3piecechickendi 

You can use a LookML Case statement or SQL Case WHEN in the LookML to define a new field. This article outlines both structures. Or, with a custom field, you can use the new case function outlined here


SQL CASE
dimension: semester {
sql: CASE
WHEN ${TABLE}.status = 0 THEN 'Fall'
WHEN ${TABLE}.status = 1 THEN 'Winter'
WHEN ${TABLE}.status = 2 THEN 'Spring'
ELSE 'Summer'
END ;;
}



LookML CASe

dimension: semester {
case: {
when: {
sql: ${TABLE}.status = 0 ;;
label: "Fall"
}
when: {
sql: ${TABLE}.status = 1 ;;
label: "Winter"
}
when: {
sql: ${TABLE}.status = 2 ;;
label: "Spring"
}
when: {
sql: ${TABLE}.status = 3 ;;
label: "Summer"
}
}
}

Thanks,

Eric

Hi @3piecechickendi 

You can use a LookML Case statement or SQL Case WHEN in the LookML to define a new field. This article outlines both structures. Or, with a custom field, you can use the new case function outlined here


SQL CASE
dimension: semester {
sql: CASE
WHEN ${TABLE}.status = 0 THEN 'Fall'
WHEN ${TABLE}.status = 1 THEN 'Winter'
WHEN ${TABLE}.status = 2 THEN 'Spring'
ELSE 'Summer'
END ;;
}



LookML CASe

dimension: semester {
case: {
when: {
sql: ${TABLE}.status = 0 ;;
label: "Fall"
}
when: {
sql: ${TABLE}.status = 1 ;;
label: "Winter"
}
when: {
sql: ${TABLE}.status = 2 ;;
label: "Spring"
}
when: {
sql: ${TABLE}.status = 3 ;;
label: "Summer"
}
}
}

Thanks,

Eric

Thank you, but is there a way to do it in Table Calculation? I’ve used this--if(${product_viewed.brand}="Levi's","Barbie",${product_viewed.brand})--but not sure how to accomplish this for multiple conditions

Hi @3piecechickendi

We would nest conditions or even use an AND or OR condition. 

7f028fc2-70aa-411b-a4b5-9b165bffd704.png

Thanks,

Eric

antho
Participant IV

Hello,

I’m adding another way if you are running the latest version of the Looker software:

https://docs.looker.com/exploring-data/adding-fields/custom-measure#custom_grouping

I found this new feature pretty cool and far more intuitive to use than nested if table calculations 🙂

Antho

Top Labels in this Space
Top Solution Authors