Overview
The html
and link
parameters can be used to create custom drill paths in dimensions or measures by creating links to related Explores, Looks, or dashboards.
Custom Drill Using HTML
Following the example below, we can click on a value in the name
dimension in Dashboard A, and drill to a related Dashboard B that is filtered on the value we clicked on. To do this, we can insert the URL of our target dashboard into an <a href="...."> </a>
tag. After applying our HTML
parameter, our name
dimension will look like this:
dimension: name { sql: ${name};; html: <a href="/dashboards/dashboardnumber?NameFilter={{ value }}&Filter2=filter_value">{{ value }}</a> ;; }
This approach assumes that we have a global filter, called name_filter
and based on the name
dimension, on the dashboard to which we are drilling. This name_filter
filter will accept the value from Dashboard A that we click on to drill to Dashboard B. By using the Liquid variable {{ value }}
, we can insert the name
value we select on Dashboard A into the filter of the dashboard URL, which will dynamically filter our target dashboard by the selected value.
User-Defined vs LookML Dashboards
Note that while the URL filter syntax for User-Defined Dashboards (UDDs) is case sensitive and does not incorporate spaces, LookML dashboard URLs are referenced using their affiliated model, name, and special characters:
dimension: name { sql: ${name};; html: <a href="/dashboards/model::dashboard_name?name_filter={{ value }}&filter_2=filter_value">{{ value }}</a> ;; }
Drill to an Explore
The URL for an Explore drill will be slightly different. To drill to an Explore using declared fields, we can obtain the expanded Explore URL and apply the {{ value }}
variable into the filter we would like to receive the value we click on (here, we apply the variable to our view_name.filter_1
filter):
dimension: name { sql: ${name};; html: <a href="/explore/model/explore_name?fields=view_name.field_name1,view_name.field_name2,view_name.field_name3&f[view_name.filter_1]={{ value }}&pivots=view.field_2">{{ value }}</a> ;; }
To drill to an Explore using a set rather than declared fields, we can use the syntax fields=view_name.set_name
, replacing the name of the view and the name of the set with your view name and set name:
dimension: name { sql: ${name};; html: <a href="/explore/model/explore_name?fields=view_name.set_name*&f[view_name.filter_1]={{ value }}&pivots=view_name.field_2">{{ value }}</a> ;; }
Custom Drill Using Link
The link
parameter functions in a similar way to the html
parameter when it comes to custom drilling, but includes the label
and icon_url
subparameters so you can further customize how the drill link will appear to users.
Drill to a Dashboard
The following code will drill to a dashboard with state
and age
filters:
dimension: state { sql: ${TABLE}.state ;; link: { label: "Drill Dashboard" url: "/dashboards/1114?State={{ value }}&Age={{ _filters['users.age'] | url_encode }}" } }
We are again using the Liquid variable {{ value }}
to dynamically filter the target dashboard's state
filter by our selected value. In this example, we are also using the Liquid variable {{ _filters['view_name.field_name'] }}
to pass the original query's filter values into the drill link. In this case, our original query is being filtered by users.age
and this filter value is being passed into our drill dashboard's age filter.
Note that url_encode
can be applied to Liquid variables like {{ value }}
and {{ _filters }}
, to ensure that all values passed into the URL (i.e., special characters) are converted into URL-safe characters.
Note: If we use the {{ _filters['view_name.field_name'] }}
variable to pass a filter value from a dashboard, the variable must refer to a field type filter.
Drill to a Look
Our link syntax will be slightly different when drilling to a Look. Replicating our example from above for a Look, we use:
dimension: name { link: { label: "Drill Look" url:"/looks/looknumber?&f[users.state]={{ value }}&f[users.age]={{ _filters['users.age'] | url_encode }}" } }
Notice the beginning ampersand and bracketed filter values.
Drill to an Explore
This example will drill to an Explore called ecommerce
, and pass the original query's state
filter into the Explore query's state
filter:
dimension: name { link: { label: "Drill Explore" url:"/explore/model_name/ecommerce?fields=users.id,users.name&f[users.state]={{ _filters['users.state'] | url_encode }}" } }
Again, the Explore URL can be found by selecting Share from the Explore's gear menu, and copying the expanded URL. We can then replace the filter values specified in the expanded URL with the _filters
variable.
URL Encoding Other Comparison Operators
If you would like to set your drill-down filter value to a comparison operator other than equal to (=
), you can do so by URL encoding the operator.
For example, if we wanted an order_id
filter on a drill-down Look to query values that are less than (<
) the order_id
field associated with the value we are drilling into, we would partially encode the operator character (here, %3E
) and add it to the URL:
f[orders.order_id]=%3E{{ other_orders.order_id._value }}
Other special characters can be encoded with URL encoder tools, such as the URL Decoder/Encoder by Meyerweb, or the HTML URL Encoding Reference by w3schools.
Including Multiple Filters
More than one filter can be applied to drill-down Looks, dashboards, and Explores by using an ampersand (&
) to separate each filter:
dimension: name { link: { label: "Drill Look" url:"/looks/looknumber?&f[users.state]={{ value }}&f[users.region]={{ users.region._value }}&f[users.age]={{ _filters['users.age'] | url_encode }}" } }
Escaping Commas
When creating custom drills with html
and link
parameters, you can escape commas in drill values with the filterable_value
variable where you might normally use the value
variable.
The following link drills to an Explore that will filter the results by the users.city
value that is selected:
dimension: city { type: string sql: ${TABLE}.city ;; link: { label: "Drill by City" url: "/explore/model_name/explore_name?fields=users.email,users.id&f[users.city]={{ value }}" } }
If the end user clicks Santa Cruz, CA to drill to the results filtered by this city, the resulting drill-down will return all results that contain either Santa Cruz or CA.
If filterable_value
is used instead of value
, the comma will be escaped:
dimension: city { type: string sql: ${TABLE}.city ;; link: { label: "Drill by City" url: "/explore/model_name/explore_name?fields=users.email,users.id&f[users.city]={{ filterable_value }}" } }
The resulting drill-down will return all results that contain the entire string value Santa Cruz, CA
.
If we want to hard-code a filter value that contains a comma in a drill-down URL, we can escape the comma by wrapping the value in double quotes and then escaping them with a forward slash (/
):
dimension: city { type: string sql: ${TABLE}.city;; link: { label: "Drill by City" url: "/explore/model_name/explore_name?fields=users.email,users.id&f[users.city]=\"Santa Cruz, CA\"&sorts=users.email" } }