
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create a dynamic dimension using a Liquid parameter
/ 40
Create a dynamic dimension using templated filters
/ 30
Create a dynamic measure using templated filters
/ 30
Looker is a modern data platform in Google Cloud that lets you analyze and visualize your data interactively. You can use Looker to do in-depth data analysis, integrate insights across different data sources, build actionable data-driven workflows, and create custom data applications.
In this lab, you will explain how Liquid parameters and templated filters can be used to enhance interactivity by users in Looker and use Liquid parameters and templated filters to create dynamic dimensions and measures.
In this lab, you will learn how to:
Familiarity with LookML and Liquid are necessary. It is recommended to complete the Getting Started with Liquid to Customize the Looker User Experience lab before beginning this lab.
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
When ready, click Start Lab.
The Lab Details pane appears with the temporary credentials that you must use for this lab.
If you need to pay for the lab, a pop-up opens for you to select your payment method.
Notice your lab credentials in the Lab details pane. You use them to sign in to the Looker instance for this lab.
Click Open Looker.
Enter the provided Username and Password in the Email and Password fields.
Username:
Password:
Click Log In.
After a successful login, you see the Looker instance for this lab.
In LookML, we call lots of things parameters, like a dimension or measure type, sql
, and drill_fields
. There is also an object itself called a parameter, which we can call a Liquid parameter for clarity.
Parameters and templated filters use Liquid to increase interactivity in Explores, Looks, and dashboards. The use case for this is: sometimes you want more flexibility in influencing the generated SQL. When you use a dimension filter, it only ever updates the WHERE
clause of the outer query. When you use a measure filter, it updates the HAVING
clause of the outer query. Either option might be filtering your results set “too much.”
“Parameters and templated filters” is often said together in one phrase because they basically achieve the same purpose when using Liquid. The main difference is that a parameter only allows one specific, fixed value, whereas a templated filter leverages the full range of filter operators for a given data type. For a string, that would be “is equal to,” “is not equal to,” “contains,” “starts with,” etc. The differences are outlined as follows:
Using parameters and templated filters provides greater flexibility in how user inputs can influence the SQL queries written. You can use parameters and templated filters to create:
So this all sounds great, but what does this cycle of behavior look like in Looker?
Parameters are little easier to understand conceptually, so that’s where we’ll start.
Liquid parameters are defined to receive specific, hard-coded values selected by users, then these values are then passed onto the generated SQL query.
In this section, you will create a parameter and dynamic dimension within the order_items view that together enable users to choose between different order creation date fields in the Order Items Explore. Users should be able to choose between Date
, Week
, and Month
and see that the query results change depending on which is selected.
order_items
view file.To start, you need to give the user something to interact with in the UI. This would be the parameter
object. Give it a name as you would a dimension or measure: select_timeframe
. The type should be unquoted, because you don’t want Looker to generate single quotes around the value for us.
Next, hard-code one or more allowed_values. The value
sub-parameter is what actually gets plugged into the SQL query, and the label
sub-parameter determines how the value is displayed in the UI. You can also choose to set one of these allowed_value
values as the default_value
. For this, you can select the month.
You will now create the Liquid parameter that can receive the user input; only three values are hard-coded and thus available for the user to select: created_date
, created_week
, and created_month
.
drill_fields
):To recap, the sub-parameters are defined as follows:
Your file should now resemble the following:
Next, you may want the fields displayed in a dashboard or Look to be dynamic, based on a user's selection of the metrics or data granularity they wish to see. Now you can use the LookML parameter you just created to apply this parameter to a dimension that ties the parameter's filter values to your different timeframe fields.
The specified timeframe field will now be returned based on whichever parameter value the user selects on the dashboard. Note that you are using label_from_parameter to pass the selected value label to your tile.
Because the ${created_week}
and ${created_month}
timeframes—and possibly ${created_date}
, depending on your database dialect—are cast by Looker to strings, the overall dynamic_timeframe dimension needs to be a string to accommodate.
This means, when business users are using this dimension in an Explore, they’ll need to remember to double-check the sort order. Looker’s default sort behavior is: check if there is a date or time dimension; if there isn’t, then sort by the first measure. So since this is technically a string type, Looker will sort by the measure first, which will likely mess up the chronological order.
You might wonder, well, what is the point then? Isn’t this introducing unnecessary complexity? Two things to keep in mind: Most business users of Looker are viewers, not explorers. That means they are looking at prepared dashboards and Looks, and they aren’t able to pick and choose different fields such as Created Date vs. Created Week in an Explore. Filters are the only way they can change what they’re seeing.
Since viewer users would be looking at content created by someone else, the fact that dynamic_timeframe
is technically a string and needs to be manually sorted has zero impact on them.
Your file should now resemble the following:
label_from_parameter
and in the sql parameter. In the visualization tab, the timeframe option will show up as Month, Week, Date, rather than the name of the dimension (Dynamic Timeframe).
Now you can test the dynamic dimension in the Order Items Explore.
Click Save Changes. Next, navigate to the Order Items Explore.
Under the Order Items view, select the new Dynamic Timeframe dimension and the Order Count measure.
Click on the filter icon next to the new Filter-Only Field called Select Timeframe
For the filter option at the top of the UI, leave “is” selected.
Select Month
from the drop-down menu.
Next, select the Week and Date filters. Click Run to see the updated results for each of them.
For each run, click the SQL tab to review how the parameter is changing and is inserted into the SQL query.
Navigate back to the Order Items view.
Click Validate LookML and then click Commit Changes & Push.
Add a commit message and click Commit.
Lastly, click Deploy to Production.
Click Check my progress to verify that you've performed the above task.
Templated filters follow the same logical pattern as parameters. Again, the major difference is that templated filters allow end users to choose from a number of filter operators. For the number data type, that could be “is equal to,” “is greater than,” “is between,” and so on.
In filters, values are not hard-coded; they are entered by users and then passed onto the generated SQL query. However, you can display a drop-down menu of options by specifying an explore and dimension in the filter definition.
In this section, you will create a dynamic dimension that takes an input value for product category and creates two groups in the results: the original category selected and all other categories.
Same as with Liquid parameters, first you need to create something in the UI for the end user to interact with. For a templated filter, you need a filter object.
explore: products {}
) that only queries the base view required for the suggested values.
As you can see, you cannot hard-code allowed_values
for templated filters as you can for parameters.
suggest_explore
and suggest_dimension
to provide a drop-down menu of filter suggestions to the end users:To recap, the sub-parameters are defined as follows:
Your file should now resemble the following:
Next, implement the user’s filter input somewhere. You will now define the dynamic dimension in the same view file.
Templated filters are referenced inside of a Liquid block using the syntax {% condition filter_name %}
. This prepares the Liquid to apply a templated filter. Then give it the name of the field you want to apply that filter to, and finish the Liquid block with an {% endcondition %}
tag. Notice how this is a little different from how you referenced a parameter; here you need to designate a field to apply the templated filter to, and an endconditon.
sql
parameter:Here you are taking the user's filter criteria from select_category
, and are applying it to the ${category}
dimension. If a category value does indeed meet the criteria, it should be displayed in the category_comparison
dimension. If a category value does not meet the criteria, it should be lumped in with all the others that don’t match as ‘All Other Categories’.
Your file should now resemble the following:
Now you can test the dynamic dimension in the Order Items Explore.
Click Save Changes. Next, navigate to the Order Items Explore.
Under the Products view, select the dimension called Category Comparison.
Click on the filter icon next to the new Filter-Only Field called Select Category (note: this is the templated filter and is listed under the Products view above the Dimensions list.)
Under the Order Items view, select the Order Count measure.
For the filter option at the top of the UI, leave “is equal to” selected.
Click in the empty text box to see the drop-down menu, or type Jeans
(you will also see other possible values in a drop-down menu).
Templated filter logic adapts automatically as the user updates the filter. See this for yourself:
Click on the SQL tab to review the SQL after each run.
Click Validate LookML and then click Commit Changes & Push.
Add a commit message and click Commit.
Lastly, click Deploy to Production.
Click Check my progress to verify that you've performed the above task.
You can combine templated filters with a hidden dimension to adjust the filter criteria of a filtered measure, resulting in dynamic measure values.
For example, a common use case for a marketing team is the need to analyze the share of users coming from each traffic source. In this section, you will be able to address this use case by creating a measure that allows a user to choose any available Traffic Source and see a dynamic count of users (by dimension, such as country) for the selected traffic source.
Again, you first need to create something in the UI for the end user to interact with. For a templated filter, you need the filter object.
drill_fields
):No values are hard-coded, but there are suggested values for an explore and dimension, which will be used to populate a drop-down menu available to users. Users can still input other values.
order_items
and the dimension to users.traffic_source
.
Your file should now resemble the following:
sql
parameter:Your file should now resemble the following:
Your file should now resemble the following:
Now you can test the dynamic measure in the Order Items Explore.
Click Save Changes. Next, navigate to the Order Items Explore.
Under the Users view, select the Country dimension (or some other dimension to get a count by attribute).
Select the new Dynamic Count measure under the Users view.
Click on the filter icon next to the new Filter-Only Field called Select Traffic Source (note: this is the templated filter and is listed in the left menu of the Explore above the Dimension.
For the filter value at the top of the UI, leave “is equal to” selected.
Click in the empty text box to see the drop-down menu, or type Email
(you will also see other possible values in a drop-down menu).
Click Check my progress to verify that you've performed the above task.
Try playing around with some other filter values, and click the SQL tab to review how the parameter is changing and is inserted into the SQL query for each run.
Navigate back to the Users view.
Click Validate LookML and then click Commit Changes & Push.
Add a commit message and click Commit.
Lastly, click Deploy to Production.
In this lab, you used Liquid in Looker to create parameters, templated filters, and dynamic dimensions and measures. You started by creating a parameter and dynamic dimension that together enabled users to choose between different order creation date fields. You then created a dynamic dimension that took an input value for product category and created two groups in the results: the original category selected and all other categories. Lastly, you created a dynamic measure that allowed a user to choose any available traffic source and see a dynamic count of users for it.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated November 13, 2024
Lab Last Tested November 13, 2024
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
此内容目前不可用
一旦可用,我们会通过电子邮件告知您
太好了!
一旦可用,我们会通过电子邮件告知您
One lab at a time
Confirm to end all existing labs and start this one