Liquid variable {{ view.field._value }} in HTML/link parameters add fields into the SQL or "Why is this field appearing in my query?"

Knowledge Drop

Last tested: Dec 7, 2020
 

When you define an html/link parameter that references a foreign value {{ view.field._value }} or {{ field._value }} Looker will pull this field into the SQL query in order to grab the value to assign this liquid variable to. Because of this, liquid can affect how SQL queries are generated, and how many columns the GROUP BY clause uses.

measure: count_without_liquid_link {
type: count
}

measure: count_with_liquid_link {

type: count

link: {

label: "Hello World!"

url: "https://www.google.com/search?q={{ status._value }}"

}

}

SQL Query generated without using foreign liquid variable:

Screen Shot 2018-10-19 at 2.51.42 PM.png

SQL Query generated when using foreign liquid variable:

Screen Shot 2018-10-19 at 2.51.53 PM.png

Example of how returned results can be confusing

Screen Shot 2018-10-19 at 2.52.26 PM.png

Alternative:
You can use row[] based liquid reference as shown below, which does not force the referenced field into the query. Note that when using this syntax, the link will only work if the field WAS selected or included in the query by some other means.

link: {

label: "{% if row['view_name.field_name'] %}some label{%endif%}"

url: "https://www.google.com/search?q={{ row['view_name.field_name']}}"

}

Code Explanation... The use of of the row[] syntax will NOT cause the field to be added to the query like {{ field_name._value }} does. The dynamic label will cause the link to have no label if the field is not available, which will cause the link to disappear from the link menu.

Help center article

This content is subject to limited support.                

Version history
Last update:
‎05-07-2021 09:48 AM
Updated by: