Question

Passing dashboard filters in a link to another dashboard

  • 9 June 2017
  • 9 replies
  • 3300 views

Userlevel 3
Badge

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.


9 replies

At the top of this article I have added a link to our documentation on Passing a Query’s Filter Values Into a Link. Hope that helps!

Hey @erin.alexander,


Is it possible to pass through more than one query filter values through a link to a Look?


dimension: name {

link: {

label: “Average Order Profit Look”

url: “https://learn.looker.com/looks/249?&f[users.state]={{ _filters[‘users.state’] | url_encode }}”

}


What would the format be?


Thanks,


Kieran

Great question! Yes, you can pass through more than one query using & (for dashboards) or &f (for Looks and Explores). Example:


dimension: name {
link: {
label: "Business Pulse By State Dashboard"
url: "https://learn.looker.com/dashboards/694?State={{ _filters['users.state'] | url_encode }}&Date={{ _filters['orders.date'] | url_encode }}"
}
link: {
label: "Average Order Profit Look"
url: "https://learn.looker.com/looks/249?&f[users.state]={{ _filters['users.state'] | url_encode }}&f[orders.date]={{ _filters['orders.date'] | url_encode }}"
}
}

Thanks for the question, I’m going to add this information to our documentation as well!

Thanks @erin.alexander this feature is so useful!

Glad to hear it! I passed this onto the engineer who worked on it. 🙂

Userlevel 4

Please note:


We have deprecated support for some of the Liquid functions/parameters used in the original solution.


The following is an updated approach:


dimension: drilltodash_example_6 {
label: "Category Linked to Dashboard"
description: "When we drill into this field, we will be navigated to another dashboard and pull in filters from the original dashboard"
type: string
sql: ${TABLE}.field ;;
link: {
label: "Category & Brand Info"
url: "/dashboards/16?Category={{ value | url_encode }}&Brand={{ _filters['products.brand'] | url_encode }}"
}
}

This used to be a great feature that we relied on quite heavily, however, since looker 7.8 the usefulness of this feature has dramatically reduced as looker now validates the filters used, breaking code if the filter used in liquid has not been joined to all explores where the dimensions have been joined. In our case we used the same dimension across multiple explores that are separate entities, and not joined. This allowed a link between separate explores for drilling, and if some filters didn’t exist then they simply weren’t pulled through, which was completely acceptable. Now we have to re-architect a project and months of work.

Hi Max, Is the same functionality available in User-defined dashboards i.e. when building dashboards using UI?

How can we pass Cross-Filter values between Dashboards via Hyperlinked Dashboards?
Filters:
https://domain.looker.com/dashboard/####?Selected<--->&tile_id####.<tile_name>.filter_field=value

 

how can we dynamically pic the value of tile level filter selected by user and pass it to other dashboards linked via URL.

Reply