This article highlights great ways to use Looker's parameter
field with some of the label
subparameters that accept Liquid variables.
Here are a few examples for some especially useful labels.
view_Label
Looker's view_label
parameter is used for grouping dimensions together under a more contextual, user-friendly name in the Explore menu. You can read more detail in the view_label
parameter's documentation page.
When you assign the same view_label
to a bunch of dimensions, it cleans things up nicely.
Example:
dimension: cost {
view_label: "Finance & Accounting"
type: number
sql: ${TABLE}.COST ;;
}
dimension: cost_ex_vat {
view_label: "Finance & Accounting"
type: number
sql: ${TABLE}.COST_EX_VAT ;;
}
dimension: cost_eur {
view_label: "Finance & Accounting"
type: number
sql: ${TABLE}.COST_EUR ;;
}
However, if, say, Bob from accounting suddenly decides he does not like his team's name, and he wants to change it to The Money Zone
instead, here is what we can do.
We can initially create a type of pseudo-variable, using Looker's parameter
field, so that we only need to change the name once and all the rest of the fields will update.
parameter: view_label {
type: string
default_value: "The Money Zone"
}
dimension: cost {
view_label: "{% parameter view_label %}"
type: number
sql: sql: ${TABLE}.COST ;;
}
dimension: cost_ex_vat {
view_label: "{% parameter view_label %}"
type: number
sql: ${TABLE}.COST_EX_VAT ;;
}
dimension: cost_eur {
view_label: "{% parameter view_label %}"
type: number
sql: ${TABLE}.COST_EUR ;;
}
Note: If you don't want the quotation marks to appear in the menu, the parameter
must be set as type:unquoted
and the default_value
must be a string without spaces, for example The_Money_Zone
. If the parameter is type:string
, the quotation marks will appear.
Label
In a situation where you have different groups of users who might interpret a field's name differently, you might want to have the name display differently for each group. For this, we can combine user attributes and Liquid variables to deliver the result.
Example:
dimension: gross_margin {
label: "{% if _user_attributes['customer'] == 'A' %} Standard Margin
{% elsif _user_attributes['customer'] == 'B' %} Operating Margin
{% else %} Gross Margin {% endif %}"
type: number
value_format_name: usd
sql: ${sale_price} - ${inventory_items.cost} ;;
}
User A
User B
This is also a pretty neat way to do some low-level localization on a user-by-user basis!
Another Example
One very specific use case is when an Explore name and a view label have separate contexts (i.e. an Explore labeled "Company Sales", and a view labeled "The Money Zone"), but you also need to add another dynamic nuance: a field label by region.
For example, if you have two measures that the East and West teams will be viewing, you might want to be dynamic about the label. In the following example, we have created two Explores from the same underlying view, order_items
using the view_name
parameter: Finance_East
and Finance_West
. The view_name
parameter allows us to alias an Explore by specifying the underlying view. Next, we use an explore_label
to display the same name for the two aliased Explores ("Company Sales"), to create an otherwise identical exploring experience for both teams. Finally, we will customize the labels of the measures to distinguish a team's region by leveraging the {{ _explore._name}}
Liquid variable, which will capture and display the Explore name.
The Measures:
measure: total_profit {
label: "{{ _explore._name}}: Profit"
type: sum
sql: ${profit} ;;
}
measure: total_revenue {
label: "{{ _explore._name}}: Revenue"
type: sum
sql: ${sale_price} ;;
value_format_name: usd
}
The Explores:
explore: Finance_East{
from: order_items
label: "Company Sales"
view_label: "The Money Zone"
explore: Finance_West{
from: order_items
label: "Company Sales"
view_label: "The Money Zone"
When exploring, the East team will see the following in the left-hand field picker:
whereas the West team will see the following:
Check out our Liquid Variable Reference for more ways to use Liquid in your LookML, and our documentation on Changing the Explore Menu and Field Picker for more ways to customize how fields appear to your users.