Join us in Las Vegas on June 13-16 for the Snowflake Summit

Learn More
Get Started Transforming Your Data in Snowflake

Is it possible to tie a dashboard filter in Looker to multiple fields in the same Look?

  • Looker FAQs
  • January 15, 2018

We can tie filters in Looker to multiple fields in the same look via Liquid syntax only.

Liquid Variable Reference

Liquid is a templating language that we can use in Looker to create more dynamic content. For example, we could build URLs to external tools based on the results of a query or change which database table is queried based on a user’s selection.

Liquid statements are built from variables, filters, and tags. Variables contain information that we want to use, and the variables that Looker provides are described below. We can further modify those values using filters and tags, which we can read about in this Liquid guide.

  • There are several places in LookML that we can use Liquid:
  • The action parameter
  • The description parameter of a field (but not of an Explore)
  • The HTML parameter
  • Label parameters at the field level, including the label parameter, view_label parameter, group_label parameter, and group_item_label parameter
  • The link parameter
  • Parameters that begin with SQL (such as SQL and sql_on)
  • The default_value dashboard filter parameter
  • The filters dashboard element parameter

Using Liquid Variables

The basic usage of Liquid variables is straightforward. Once we have identified the variable we would like to use (all listed below), insert it into a valid LookML parameter. The specific Liquid variables that we can use in specific LookML parameters are defined below.

Two Kinds of Liquid Usage

There are two ways to make use of a Liquid variable:

  • Output Syntax: This type of usage can insert text and is probably the most common way to use Liquid in Looker. In this method, we enclose the Liquid variable in two curly braces. For example: {{ value }}
  • Tag Syntax: This type of usage usually doesn’t insert text; instead, it is for logical comparisons and other Liquid operations. In this method, we enclose the Liquid variable in one curly brace and a single percent sign. For example: {% if value > 10000 %}

Basic Examples

Ex:1 In this example of HTML usage, a product ID is being inserted into a <img> tag to generate product images:

dimension: product_image {
sql: ${product_id} ;;
html: <img src="http://www.brettcase.com/product_images/{{ value }}.jpg" /> ;;
}

Ex:2 In this example of URL usage, an artist’s name is inserted into a URL to produce a Google search for that artist.

dimension: artist_name {
sql: ${TABLE}.artist_name ;;
link: {
label: "Google"
url: "http://www.google.com/search?q={{ value }}"
icon_url: "http://google.com/favicon.ico"
}
}

Ex:3 In this example of SQL usage, the database table is being determined according to which fields the user chooses. The syntax uses an if, else if (denoted as elsif), else structure to check and react to the fields included in the query.

sql_table_name:
{% if event.created_date._in_query %}
event_by_day
{% elsif event.created_week._in_query %}
event_by_week
{% else %}
event
{% endif %} ;;

For additional usage examples, see the individual LookML parameter page you’re interested in.

Accessing Variables from Other Fields

Liquid variables are usually based on the field where they are being used. However, we can also access values from other fields if needed.
Use the format {{ view_name.field_name._liquid-variable-name }} to access other fields from the same row in the query result. Replace _liquid-variable-name with any of the Looker Liquid variables. Make sure an underscore precedes the variable name if it isn’t normally, like these:

{{ view_name.field_name._value }}
{{ view_name.field_name._rendered_value }}
{{ view_name.field_name._model._name }}
This example shows this type of usage to access a website URL from a different field:

dimension: linked_name {
sql: ${name} ;;
html: <a href="{{ website.url._value }}" target="_new">{{ value }}</a> ;;
}

Warning

When you reference another field using the {{ field_name._value }} Liquid variable syntax, the referenced field is added to the SELECT clause of the SQL query and added as an additional column in the GROUP BY clause. This is necessary to retrieve the values in the referenced field properly. But it can cause unexpected results in aggregate measures. For more information, see the Using Liquid Variables in Aggregate Measures Help Center article.

Things to Consider

Referencing yes/no Fields

To reference a yes no field’s value, the value is case sensitive. Use Yes or No. For example:

{% if value == 'Yes' %}

Using Logical Operators with Liquid Variables

We can use the logical operators and, or, and not with Liquid variables. Logical operators in Liquid are case-sensitive and must be written in all lower-case. For example:

{% if value == "Shirt" or value == "Shoes" %}
This is a shirt or shoes.
{% endif %}

Getting the “Variable not found” Error

One reason we might get this error in Liquid is if you use {{ }} and {% %} at the same time, like this:
{% if value > {{ search_latency_top_hr.limit_95._value }} %}

Instead, do this:

{% if value > search_latency_top_hr.limit_95._value %}

If we are using a templated filter, then check whether we are referencing a table name that we have not joined into the derived table.


Up Next:

Read How to create a funnel chart visualization in Looker?

More Resources We Think You Might Like

How to create a funnel chart visualization in Looker?

How to create a funnel chart visualization in L...

A Funnel chart is best used to understand the linear sequence of events, such as search movement ...

  • Looker FAQs
  • January 15, 2018
How to create a funnel chart visualization in Looker?

How to add custom visualization in Looker using...

In Looker, there are two ways to add custom visualizations using Javascript: Adding a custom visu...

  • Looker FAQs
  • January 15, 2018
How to create a funnel chart visualization in Looker?

How to show the column value labels in Looker

This post explains how to show the column value labels in Looker without changing the value label...

  • Looker FAQs
  • January 15, 2018