Using Liquids _filters Variable for Dashboard Linking

liquid
html
link
dashboards
lookml

(vincent) #1

Use Case

From to time, end users would like to navigate to a dashboard from an explore while being allowed to bring the filter values from the explore. In the past, this was only possible with row level values or writing some gnarly liquid syntax. With Lookers (somewhat) new _filters liquid variable, this is now possible!

Scenario

In my eCommerce example, I have a dashboard, with a Look, that shows Orders by States in the US. What I would like to do, is, if an end user is running an Explore with the User State dimension while filtering on it, they have the ability to link out to the dashboard while filtering on the same State value.

LookML

Now that we have an idea of what we would like to present to the end user, lets go ahead and write some LookML/Liquid to achieve this. But before we do, lets make sure that a dashboard exists and a field filter using User State dimension also exist, like so:

Awesome, now that we have that out of the way, lets grab the URL for the dashboard.

https://learn.looker.com/dashboards/58?State=
Perfect. Next step, switch to development mode, if not already, and navigate to the eCommerce project and Users view file. Then find the state dimension and create a link parameter. Then we will provide a reasonable label, the URL, and an icon. The url: parameter is where we will be providing the dashboard url from earlier. We will also want to use attach the {{ _filters[ 'view_name.field_name' ] }} variable after the State= parameter in the URL. In the end, you will end up withg something like:

  dimension: state {
    type: string
    sql: ${TABLE}.state ;;
    link: {
      label: "eCommerce Dashboard"
      url: "https://learn.looker.com/dashboards/58?State={{ _filters['users.state'] | url_encode}}"
      icon_url: "https://looker.com/favicon.ico"
    }
  }

I added the | url_encode because sometimes, you might have values that need to be URL encoded or it will break the filter URL. That is all, so now lets test it out on an explore.

End Results

Here is an explore that shows me how many users are from California:


Sweet, as you can see, the link bubbles are there. Clicking on it will provide a link to the dashboard and pass the California value along with it:

And voila, success!