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! Go to Solution.
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
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
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