Question

Dynamic labeling can use Liquid?

  • 1 June 2018
  • 1 reply
  • 2065 views

Can liquid variables be used to change the dimension labels for a field to the value of a field ?


I have a table like:


create table kv (


id int,


subid int,


key varchar(100),


val varchar(255),


updated_at timestamp


)


primary key (id, subid, key);



Something like:


dimension: key_value {


type: string


label: “{% ${TABLE}.key %}”


sql: ${TABLE}.val


filters: {


field: id,


value: _user_attributes[‘customer’]


}


}



Is close to what I am thinking.



The latest subid will have all the unique ${TABLE}.key to use as labels. No need to get values from anything but the latest subid.



Thanks.


1 reply

Userlevel 7
Badge +1

Michael,



This is an interesting use case idea-- Liquid can be used in the label parameter (see https://docs.looker.com/reference/field-params/label-for-field#liquid_variables_with_label), but per our liquid documentation, (the{{ value }} syntax cannot be used in the label parameter, mostly because usually columns return more than 1 row, which would make use of the {{ value }} parameter difficult since it wouldn’t know which row to reference.



You could do some kind of nested if() statement using the user_attribute value or something else that might let you return dynamic values, but they’d have to be manually entered.



I’ll pass this idea along to our product team, along with your example for context!



Best,


Izzy

Reply