Question

Renaming values based on mapping

  • 23 August 2017
  • 3 replies
  • 1915 views

Hello,



I have numeric columns in my data and would like to replace those values in my look. Is this supported or is there additional documentation where this is outlined?



1 = Sunday


2 = Monday


3 = Tuesday etc.




3 replies

So I found the docs on time formatting which should help with this.





Userlevel 3

@Jack_Martin,



On the front end, you could achieve this with nested if statements in a table calculation.



Something like:


if(${day_of_week}=1,"Monday" ,if(${day_of_week}=2,"Tuesday" ,if(${day_of_week}=3,"Wednesday" ,"etc.")))



All of the functions we can use within table calcs are documented here. With the above table calc we would need to hide the orginal dimension from the vis.



If we want to do it in LookML we can use a case statement (documented here).



For your example it would be something like:



  case: {

when: {

sql: ${TABLE}.week_day = 1 ;;

label: "Monday"

}

when: {

sql: ${TABLE}.week_day = 2 ;;

label: "Tuesday"

}

when: {

sql: ${TABLE}.week_day = 3 ;;

label: "Wednesday"

}

else: "etc."

}

}



Feel free to visit us at help.looker.com if you’re running into any issues implementing a specific solution.

Userlevel 3

We can now use this nested if statement from @rufus’ solution above using Looker’s new Custom Dimensions.



Unlike a table calculation we can refer to a field from the explore in a custom dimension whether or not it is included in the query’s result set.

Reply