Overview
In a challenge lab you’re given a scenario and a set of tasks. Instead of following step-by-step instructions, you will use the skills learned from the labs in the course to figure out how to complete the tasks on your own! An automated scoring system (shown on this page) will provide feedback on whether you have completed your tasks correctly.
When you take a challenge lab, you will not be taught new Google Cloud concepts. You are expected to extend your learned skills, like changing default values and reading and researching error messages to fix your own mistakes.
To score 100% you must successfully complete all tasks within the time period!
This lab is recommended for students who have enrolled in the Manage Data Models in Looker skill badge. Are you ready for the challenge?
Topics tested
Troubleshoot and fix LookML Code
Create a refinement with an aggregate table
Extend a view
Create and apply a datagroup to LookML objects
Group fields
Utilize different parameters to customize LookML objects
Setup and requirements
Before you click the Start Lab button
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 will be 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:
- Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
- Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.
How to start your lab and sign in to Looker
When ready, click .
A new panel will appear with the temporary credentials that you must use for this lab.
If you need to pay for the lab, a pop-up will open for you to select your payment method.
Note your lab credentials in the left pane. You will use them to sign in to the Looker instance for this lab.
Note: If you use other credentials, you will get errors or incur charges.
Click Open Looker.
Enter the provided Username and Password in the Email and Password fields.
Important: You must use the credentials from the Connection Details panel on this page. Do not use your Google Cloud Skills Boost credentials. If you have your own Looker account, do not use it for this lab.
Click Log In.
After a successful login, you will see the Looker instance for this lab.
Challenge scenario
You have been hired as a LookML developer for a new cutting-edge e-commerce company. The company's infrastructure is run solely on Google Cloud and uses Looker for their data platform to analyze and integrate insights across different data sources.
For your first assignment, you have been tasked with updating your company's existing LookML code base to reflect best practices and optimize performance to reduce cost and time to analyze the data. However, upon reviewing the code base, you've found numerous instances where certain code blocks were broken, incorrectly implemented, or simply do not adhere to Looker best practices. You have been instructed to update and fix this code to help your data analysis team leverage the Looker data without any issues.
You are expected to have the skills and knowledge for these tasks, so step-by-step guides are not provided.
Task 1. Create LookML objects
When going through your company's LookML code base, you found a refinement that includes a weekly profit and revenue aggregate table. You assume that Looker will use this aggregate table for total profit and revenue queries that can leverage weekly granularity. The code for the refinement, however, contains errors and is only half-implemented. Furthermore, you also notice that the refinement contains objects that haven't been created yet.
To start, you will first need to create these LookML objects and then fix the refinement and aggregate table in the next section.
- Inside of the order_items view, create a new dimension and a new measure that calculate profit and total profit.
Requirements:
Name these objects
profit
andtotal_profit
.You need to use
profit
to createtotal_profit
.For both
profit
andtotal_profit
, set the value_format_name parameter tousd
(US Dollars).Following best practices, you will need to add a description and label to both the measure and the dimension.
Note: You can use SQL Runner to review the product table vs. the order_items table to help you determine which fields you should use to define these new LookML objects.
- Inside of the training_ecommerce.model file, create a new datagroup.
Requirements:
Name the datagroup:
weekly_datagroup_KAGj
.Set a maximum cache age of one week (168 hours). For the purposes of this challenge, you do not need to include an
sql_trigger
. You may receive a warning message which you can ignore for the purposes of this lab.Set the
weekly_datagroup_KAGj
as the caching policy to use for all Explores in the model.
Click Validate LookML to validate your code.
Click Commit Changes and Push, then click Deploy to Production.
Click Check my progress to verify the objective.
Create LookML objects
Check my progress
Task 2. Create and fix a refinement with an aggregate table
Now that the objects referenced in the refinement and aggregate table have been properly created, you are ready to troubleshoot and fix the pre-existing code. In this section, you will be given broken LookML code for a refinement with an aggregate table that you will need to troubleshoot and fix. You will need to use the LookML objects you created in the previous section to complete this task.
- Start by copying the following code into the training_ecommerce.model file, under the Events explore:
explore: +order_items {
label: ""
aggregate_table: weekly_aggregate_revenue_profit {
query: {
dimensions: []
measures: []
}
materialization: {
datagroup_trigger: weekly_datagroup
increment_key: ""
}
}
}
Copied!content_copy
Click Save Changes then Validate LookML to see some of the errors that the code introduces.
Fix the refinement and aggregate table LookML code. Requirements:
Include a label for the refinement named:
Order Items - Aggregate Profit and Revenue
.The query for the aggregate table must include the following dimensions and measures from the order_items view:
created_date
,total_revenue
,total_profit
.A datagroup_trigger that references
weekly_datagroup_KAGj
(which you created in the previous section). Be sure to include a time increment that referencescreated_date
to identify the time step for appending new data.
Click Commit Changes and Push, then click Deploy to Production.
Create a visualization
From the Order Items - Aggregate Profit and Revenue Explore, select Order Items > Created Date > Month, Total Revenue, and Total Profit. Make sure your Created Month column is in Ascending order.
Create a Line visualization. It should resemble the following:
- Save this visualization as a Look and name it:
Monthly Profit and Revenue (Challenge 0NXv)
.
Click Check my progress to verify the objective.
Create a visualization
Check my progress
Task 3. Extend a view
Now that you have fixed the code for the refinement and aggregate table, you have been requested to create a separate view that contains users' personally identifiable information (PII) and can be extended from other views.
This will enable future work to hide the PII from some teams, so that only people with certain levels of access will be able to see it. For the time being, all you need to do is create the extend for the PII and test that it can be extended from other views.
In this task, you will create a new view that contains user PII dimensions and test that it works by extending it from the existing users view.
Create new view named
user_pii_challenge_R28T
. Place it in the views folder.Remove all the placeholder code, and add the following dimensions:
first_name
,last_name
,email
,id
,latitude
, andlongitude
.
Note: These dimensions are already defined in one of the existing views.
- Extend this view from the users view.
Requirements:
Set the
id
dimension as the primary key.Add the correct parameter to require extension for this view. The contents and settings of this view can only be used when the view is extended using the extends parameter in another view.
Add the proper code to extend users.view using the
user_pii_challenge_R28T
view.Hide the LookML code for the same PII dimensions in users.view.
Run a query in the Explore to test that the dimensions are now provided from successfully extending users.view using the
user_pii_challenge_R28T
view.
Click Validate LookML to validate your code.
Click Commit Changes and Push, then click Deploy to Production.
Click Check my progress to verify the objective.
Extend the view
Check my progress
Task 4. Group similar fields in views
For your final task, a data analyst on your team has requested you to group specific dimensions and measures for their business requirements. In this task, you will create two groups: one for general user information and one for product information. You will then add the associated dimensions and measures to each.
Use the correct parameter to group the following dimensions in the users view into a new group named
User Information (Challenge JxH7)
:Age
City
Country
State
Create another group named
Product Information (Challenge 6awk)
that includes the following dimensions in the products view:Brand
Category
Department
Name
Verify these groups are working as intended in the Explore by running two separate queries (one in each view: users and products) using all of the dimensions in the newly created group.
Click Validate LookML to validate your code.
Click Commit Changes and Push, then click Deploy to Production.
Click Check my progress to verify the objective.
Solution of Lab
Task 1. Create LookML objects
- Replace the following in
order_items.view
view: order_items {
sql_table_name: `cloud-training-demos.looker_ecomm.order_items`
;;
drill_fields: [order_item_id]
dimension: order_item_id {
primary_key: yes
type: number
sql: ${TABLE}.id ;;
}
dimension_group: created {
type: time
timeframes: [
raw,
time,
date,
week,
month,
quarter,
year
]
sql: ${TABLE}.created_at ;;
}
dimension_group: delivered {
type: time
timeframes: [
raw,
date,
week,
month,
quarter,
year
]
convert_tz: no
datatype: date
sql: ${TABLE}.delivered_at ;;
}
dimension: inventory_item_id {
type: number
# hidden: yes
sql: ${TABLE}.inventory_item_id ;;
}
dimension: order_id {
type: number
sql: ${TABLE}.order_id ;;
}
dimension_group: returned {
type: time
timeframes: [
raw,
time,
date,
week,
month,
quarter,
year
]
sql: ${TABLE}.returned_at ;;
}
dimension: sale_price {
type: number
sql: ${TABLE}.sale_price ;;
}
dimension_group: shipped {
type: time
timeframes: [
raw,
date,
week,
month,
quarter,
year
]
convert_tz: no
datatype: date
sql: ${TABLE}.shipped_at ;;
}
dimension: status {
type: string
sql: ${TABLE}.status ;;
}
dimension: user_id {
type: number
# hidden: yes
sql: ${TABLE}.user_id ;;
}
measure: average_sale_price {
type: average
sql: ${sale_price} ;;
drill_fields: [detail*]
value_format_name: usd_0
}
measure: order_item_count {
type: count
drill_fields: [detail*]
}
measure: order_count {
type: count_distinct
sql: ${order_id} ;;
}
measure: total_revenue {
type: sum
sql: ${sale_price} ;;
value_format_name: usd
}
measure: total_revenue_from_completed_orders {
type: sum
sql: ${sale_price} ;;
filters: [status: "Complete"]
value_format_name: usd
}
dimension: profit {
label: "profit"
description: "sgggf"
type: number
sql: ${sale_price} - ${products.cost} ;;
value_format_name: usd
}
measure: total_profit {
label: "total_profit"
description: "sgggf sum"
type: sum
sql: ${profit} ;;
value_format_name: usd
}
# ----- Sets of fields for drilling ------
set: detail {
fields: [
order_item_id,
users.last_name,
users.id,
users.first_name,
inventory_items.id,
inventory_items.product_name
]
}
}
- Replace the following in
training_ecommerce.model
& ChangeNAME_DATAGROUP
with yourNAME
in Instruction.
connection: "bigquery_public_data_looker"
# include all the views
include: "/views/*.view"
include: "/z_tests/*.lkml"
include: "/**/*.dashboard"
datagroup: training_ecommerce_default_datagroup {
# sql_trigger: SELECT MAX(id) FROM etl_log;;
max_cache_age: "1 hour"
}
persist_with: training_ecommerce_default_datagroup
label: "E-Commerce Training"
explore: order_items {
join: users {
type: left_outer
sql_on: ${order_items.user_id} = ${users.id} ;;
relationship: many_to_one
}
join: inventory_items {
type: left_outer
sql_on: ${order_items.inventory_item_id} = ${inventory_items.id} ;;
relationship: many_to_one
}
join: products {
type: left_outer
sql_on: ${inventory_items.product_id} = ${products.id} ;;
relationship: many_to_one
}
join: distribution_centers {
type: left_outer
sql_on: ${products.distribution_center_id} = ${distribution_centers.id} ;;
relationship: many_to_one
}
}
explore: events {
join: event_session_facts {
type: left_outer
sql_on: ${events.session_id} = ${event_session_facts.session_id} ;;
relationship: many_to_one
}
join: event_session_funnel {
type: left_outer
sql_on: ${events.session_id} = ${event_session_funnel.session_id} ;;
relationship: many_to_one
}
join: users {
type: left_outer
sql_on: ${events.user_id} = ${users.id} ;;
relationship: many_to_one
}
}
datagroup: NAME_DATAGROUP {
max_cache_age: "168 hours"
}
persist_with: NAME_DATAGROUP
explore: +order_items {
label: ""
aggregate_table: weekly_aggregate_revenue_profit {
query: {
dimensions: [order_items.created_date]
measures: [order_items.total_revenue, order_items.total_profit]
}
materialization: {
datagroup_trigger: NAME_DATAGROUP
increment_key: "created_date"
}
}
}
Task 2. Create and fix a refinement with an aggregate table
- Replace the following in
training_ecommerce.model
explore: +order_items {
query: awesome {
dimensions: [created_month]
measures: [total_profit, total_revenue]
}
}
Task 3. Extend a view
- Create a
.view
file & replace the following, change the.view
file name withVIEW_NAME
:
view: VIEW_NAME {
extension: required
dimension: id {
primary_key: yes
type: number
sql: ${TABLE}.id ;;
}
dimension: email {
type: string
sql: ${TABLE}.email ;;
}
dimension: first_name {
type: string
sql: ${TABLE}.first_name ;;
}
dimension: last_name {
type: string
sql: ${TABLE}.last_name ;;
}
dimension: latitude {
type: number
sql: ${TABLE}.latitude ;;
}
dimension: longitude {
type: number
sql: ${TABLE}.longitude ;;
}
}
Task 4. Group similar fields in views
- Replace the following in
user.view
& change theGROUP_NAME
.
view: users {
sql_table_name: `cloud-training-demos.looker_ecomm.users`
;;
drill_fields: [id]
dimension: id {
primary_key: yes
type: number
hidden: yes
sql: ${TABLE}.id ;;
}
dimension: age {
type: number
group_label:"GROUP_NAME"
sql: ${TABLE}.age ;;
}
dimension: city {
type: string
group_label:"GROUP_NAME"
sql: ${TABLE}.city ;;
}
dimension: country {
type: string
group_label:"GROUP_NAME"
map_layer_name: countries
sql: ${TABLE}.country ;;
}
dimension_group: created {
type: time
timeframes: [
raw,
time,
date,
week,
month,
quarter,
year
]
sql: ${TABLE}.created_at ;;
}
dimension: email {
type: string
hidden: yes
sql: ${TABLE}.email ;;
}
dimension: first_name {
type: string
hidden: yes
sql: ${TABLE}.first_name ;;
}
dimension: gender {
type: string
sql: ${TABLE}.gender ;;
}
dimension: last_name {
type: string
hidden: yes
sql: ${TABLE}.last_name ;;
}
dimension: latitude {
type: number
hidden: yes
sql: ${TABLE}.latitude ;;
}
dimension: longitude {
type: number
hidden: yes
sql: ${TABLE}.longitude ;;
}
dimension: state {
type: string
group_label:"GROUP_NAME"
sql: ${TABLE}.state ;;
map_layer_name: us_states
}
dimension: traffic_source {
type: string
sql: ${TABLE}.traffic_source ;;
}
dimension: zip {
type: zipcode
sql: ${TABLE}.zip ;;
}
measure: count {
type: count
drill_fields: [id, last_name, first_name, events.count, order_items.count]
}
}
- Replace the following in
products.view
& change the GROUP_NAME
view: products {
sql_table_name: `cloud-training-demos.looker_ecomm.products`
;;
drill_fields: [id]
dimension: id {
primary_key: yes
type: number
sql: ${TABLE}.id ;;
}
dimension: brand {
type: string
group_label:"GROUP_NAME"
sql: ${TABLE}.brand ;;
}
dimension: category {
type: string
group_label:"GROUP_NAME"
sql: ${TABLE}.category ;;
}
dimension: cost {
type: number
sql: ${TABLE}.cost ;;
}
dimension: department {
type: string
group_label:"GROUP_NAME"
sql: ${TABLE}.department ;;
}
dimension: distribution_center_id {
type: string
# hidden: yes
sql: ${TABLE}.distribution_center_id ;;
}
dimension: name {
type: string
group_label:"GROUP_NAME"
sql: ${TABLE}.name ;;
}
dimension: retail_price {
type: number
sql: ${TABLE}.retail_price ;;
}
dimension: sku {
type: string
sql: ${TABLE}.sku ;;
}
measure: count {
type: count
drill_fields: [id, name, distribution_centers.name, distribution_centers.id, inventory_items.count]
}
}
Congratulations 🎉 for Completing the Lab !