Passing dashboard filters in a link to another dashboard

Note from our Docs team: Starting in 4.18, you can use Liquid variables to pass a query’s filter values into linked queries, dashboards, and Looks, please see this page in our documentation.

Have you ever wanted to click a link in one dashboard and take all of your current filters with you? It’s possible with a lot of Liquid and a little patience. I’ve got a pattern which works below, tested on release 4.14 of Looker.

This isn’t plug and play, so you’ll have to make some changes to the Liquid to get it to work in your specific case. Check out the section below this for a step-by-step explanation of how it works!

The Pattern

  dimension: id {
    type: number
    sql: ${TABLE}.id ;;
    html: 
      {% assign url_split_at_f = filter_link._link | split: '&f' %}
      {% assign user_filters = '' %}
      {% assign continue_loop = true %}

      {% for url_part in url_split_at_f offset:1 %}
        {% if continue_loop %}
          {% if url_part contains '&sorts' %}
            {% assign part_split_at_sorts = url_part | split: '&sorts' %}
            {% assign last_filter = part_split_at_sorts | first %}
            {% assign user_filters = user_filters | append:'&f' %}
            {% assign user_filters = user_filters | append:last_filter %}
            {% assign continue_loop = false %}
          {% else %}
            {% assign user_filters = user_filters | append:'&f' %}
            {% assign user_filters = user_filters | append:url_part %}
          {% endif %}
        {% endif %}
      {% endfor %}
            
      {% assign user_filters = user_filters | replace: 'f[orders.created_date]', 'Created Date' %}
      {% assign user_filters = user_filters | replace: 'f[users.is_first_timer]', 'First Time Buyer' %}
      {% assign user_filters = user_filters | replace: 'f[products.category]', 'Category' %}            

      <a href='/dashboards/12?{{ user_filters }}'>{{ value }}</a>;;
  }

  measure: filter_link {
    type: count_distinct
    hidden: yes
    drill_fields: []
    sql: ${TABLE}.id ;;
  }

The Explanation

That’s a huge chunk of code, so let’s break it down piece by piece.

# This part splits the URL at '&f', which separates each filter parameter in the URL
{% assign url_split_at_f = test._link | split: '&amp;f' %}

# This part initializes an empty string, which we'll fill with filters
{% assign user_filters = '' %}

# We'll use this to stop looping through the URL parameters when we reach the "sorts" parameter
{% assign continue_loop = true %}

# Begin looping through each URL parameter
{% for url_part in url_split_at_f offset:1 %}

  # Only continue loop if we haven't turned it off
  {% if continue_loop %}

    # If we reached the "sorts" parameter, we need to cleave the last filter from this parameter
    {% if url_part contains '&amp;sorts' %}
      {% assign part_split_at_sorts = url_part | split: '&amp;sorts' %}
      {% assign last_filter = part_split_at_sorts | first %}

      # Tack the last filter on to the "user_filters" variable
      {% assign user_filters = user_filters | append:'&f' %}
      {% assign user_filters = user_filters | append:last_filter %}

      # Stop looping, we're out of filters
      {% assign continue_loop = false %}

    # Store the filter in our user_filter parameter, separate using '&f'
    {% else %}
      {% assign user_filters = user_filters | append:'&amp;f' %}
      {% assign user_filters = user_filters | append:url_part %}

    {% endif %}
  {% endif %}
{% endfor %}
            
# For each filter that the target dashboard uses, we'll need to replace it with the name as it appears in the dashboard filter panel
{% assign user_filters = user_filters | replace: 'f[orders.created_date]', 'Created Date' %}
{% assign user_filters = user_filters | replace: 'f[users.is_first_timer]', 'First Time Buyer' %}
{% assign user_filters = user_filters | replace: 'f[products.category]', 'Category' %}

# IMPORTANT: You will need to update these every time the target dashboard's filters change
            
# Finally, link to the target dashboard and append "?{{ user_filters }}" to the end of the URL. Display value as normal
<a href='/dashboards/12?{{ user_filters }}'>{{ value }}</a>

Additionally, we have to create a dummy measure to properly expose the dashboard filters in the URL. If we use a dimension here, this won’t work.

  measure: filter_link {
    type: count_distinct
    hidden: yes
    drill_fields: []
    sql: ${TABLE}.id ;;
  }

The important parts here are that:

  1. The field is a measure
    It doesn’t matter what type as long as it won’t cause any errors. I hide it in my example.

  2. the field has a drill_fields parameter
    It can be empty.

And that’s it! Now whenever you click this dimension in a table visualization when it is in a dashboard, it will take the values of this dashboard and apply them to the corresponding values in the target dashboard.

1 10 8,399
10 REPLIES 10
Top Labels in this Space