Parameter Calculation

aa23
New Member

Hi everyone, 

I am looking for resources/explanation how to create a Parameter in Looker Explore?

When I say parameter I mean like a same concept what Parameter means in tableau.

Eventually when I create string  single select parameter. I need to use it the custom metric calculation. Logic: When someone selects x value in the parameter my calculation will use x as denominator in the calc. 

0 2 926
2 REPLIES 2

Hello!

Parameters are a great resource in Looker. Here is their official documentation, and for your use case you may use something similar to the following:

For parameters to work you need 2 components: a parameter that allows users to choose between different options and a dimension or measure to reflect data based on the user's choice.

The parameter is what the user would use to select what metric they want to observe. If we want the user to be able to choose between how many sales have been made by different denominators, we need to create a parameter that stores those options. See below for example:

 

parameter: sales_period {
  type: string
  allowed_value: {
    label: "Sales per Customer"
    value: "customer"
  }
  allowed_value: {
label: "Sales per Store" value: "store"
}
}

Now that the user can choose between which version of the metric they want to view we have to surface their choice dynamically. In this example we can use a measure to do that ( a dimension of type: number would also work). Below we can divide a measure called sales by either a measure called number_of_customers if the user chooses the "Sales per Customer" option or by a measure called number_of_stores if the user chooses the "Sales per Store". *

 

measure: sales_per_period {
  sql:
    {% if sales_period._parameter_value == 'customer' %}
      ${sales}/${number_of_customers}
    {% elsif sales_period._parameter_value == 'store' %}
      ${sales}/${number_of_store}
    {% endif %};;
}

In the front end explore adding this measure in conjunction with the parameter will automatically change what field (x) calculation divides by from either sales per customer to sales per store, depending on which value is selected in the parameter. Hope this helps!

 

*parameter_name._parameter_value allows for complex logical statements using possible values of a parameter — similar to a CASE WHEN statement in SQL.

A Liquid conditional statement uses the following syntax:

  • {% if %} to create a condition
  • {% elsif %} to create additional conditions after the initial condition
  • {% else %} to establish a value to return when the other conditions are not met
  • {% endif %} to end the statement

This Liquid logic can be used with Liquid variables and LookML in various ways. See the Liquid variable reference documentation page for a complete list of possible places to use the parameter_name._parameter_value variable with Liquid in LookML. The following are examples that use the sql and html parameters.

Creation of Parameters in Looker Explore UI is not available the way it is done in Tableau Desktop. But it is available in LookML while creating views and explores.