home User Guide Getting Started Help Center Documentation Community Training Certification
Looker keyboard_arrow_down
language keyboard_arrow_down


view: view_name {
  parameter: parameter_name {}




A Looker identifier to name the parameter


There is a LookML parameter that is actually called “parameter”. The parameter parameter creates a filter-only field that can be used to filter Explores, Looks, and dashboards but that cannot be added to a result set. The value that a user selects for this filter-only field can create interactive query results, labels, URLs, and more when used with the {% parameter parameter_name %} and parameter_name._parameter_value Liquid variables. The parameter parameter can also simplify LookML models, as different results can be displayed in a single field.

With parameter filter fields, users can select only one filter value for a field, and the filter condition is set to is equal to. If you would like users to be able to input multiple filter values at once, and take advantage of Looker’s more nuanced generated SQL filter logic (contains,does not contain, etc.), see the Templated Filters documentation page for details.

A parameter name must:

There are also many field parameters that can be used with parameter, including allowed_value.

Specifying Allowed Values

By default, a user can input any single value into a filter created by a parameter parameter. If you want to limit the specific values that a user can choose from, use allowed_value. Allowed values specify pairs of labels and values that a user can choose.

The allowed_value parameter is similar to the suggestions parameter, in that it allows you to set the filter options a user may choose from. However, the allowed_value parameter adds the extra functionality of mapping a user-friendly label with the value you want to inject into the underlying SQL query.

For example, this would produce a parameter that gives a user three filter options:

parameter: number_of_results { type: string allowed_value: { label: "Less than 500" value: "< 500" } allowed_value: { label: "Less than 10,000" value: "< 10000" } allowed_value: { label: "All Results" value: "> 0" } }

The label is what the user will see in the filter suggestions, and value contains the value that will be inserted into SQL queries with Liquid variables to create interactive content.

The resulting filter looks like this:

Using parameter with Liquid

There are two types of Liquid usage, as referenced by the Liquid Variable Reference documentation page.

When parameter is used with Liquid, it is most common to use {% %} tag syntax, which is used to create logical conditional statements.

Two Liquid variables that you can use with parameter are: {% parameter parameter_name %} and parameter_name._parameter_value. We’ll walk through examples of each in the following sections.

Inserting User-Selected Values with {% parameter parameter_name %}

The {% parameter parameter_name %} Liquid variable uses the Liquid {% parameter %} tag in conjunction with the parameter’s name to insert a user-selected value directly into an underlying SQL query.


In this example, we create a parameter named item_to_add_up that lets a user choose what database column they want to sum — sale_price, cost, or profit:

parameter: item_to_add_up { type: unquoted allowed_value: { label: "Total Sale Price" value: "sale_price" } allowed_value: { label: "Total Cost" value: "cost" } allowed_value: { label: "Total Profit" value: "profit" } }

Next, we create a measure called dynamic_sum.

This measure references the {% parameter parameter_name %} Liquid variable in its sql parameter, which injects the selected value from item_to_add_up and changes the column name being referenced. The measure then performs the calculation on the referenced column:

measure: dynamic_sum { type: sum sql: ${TABLE}.{% parameter item_to_add_up %} ;; value_format_name: "usd" }

The result is an interactive Explore, displaying different aggregations represented by one measure, shown below:

See the Great Use Cases for Parameter Fields Help Center article for more examples of using parameter with the {% parameter parameter_name %} variable.

Creating Logical Statements with parameter_name._parameter_value

You can also inject the value of a parameter into an underlying SQL query using a logical Liquid {% %} statement with the parameter_name._parameter_value Liquid variable.

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:

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. Below are examples using the sql and html parameters.

SQL Example

The following LookML block creates a parameter named date_granularity. Then, the sql parameter of a dimension uses parameter_name._parameter_value with the {% if %}, {% elsif %}, {% endif %} logical structure to determine the value of the dimension, based on the value of the parameter:

parameter: date_granularity { type: unquoted allowed_value: { label: "Break down by Day" value: "day" } allowed_value: { label: "Break down by Month" value: "month" } } dimension: date { sql: {% if date_granularity._parameter_value == 'day' %} ${created_date} {% elsif date_granularity._parameter_value == 'month' %} ${created_month} {% else %} ${created_date} {% endif %};; }

The end result is an interactive date field that users can change to display the results in different timeframes:

HTML Example

parameter_name._parameter_value can also be used with an html parameter to create interactive results formatting.

Using the example above, we can change the text color depending on which date granularity a user selects by adding an html parameter with a similar {% if %} logical statement:

parameter: date_granularity { type: unquoted allowed_value: { label: "Break down by Day" value: "day" } allowed_value: { label: "Break down by Month" value: "month" } } dimension: date { sql: {% if date_granularity._parameter_value == 'day' %} ${created_date} {% elsif date_granularity._parameter_value == 'month' %} ${created_month} {% else %} ${created_date} {% endif %};; html: {% if date_granularity._parameter_value == 'day' %} <font color="darkgreen">{{ rendered_value }}</font> {% elsif date_granularity._parameter_value == 'month' %} <font color="darkred">{{ rendered_value }}</font> {% else %} <font color="black">{{ rendered_value }}</font> {% endif %};; }

The rendered_value Liquid variable is used in the html statement in conjunction with Liquid object tags, {{ }}, to output the value of the field with Looker’s default formatting in the results.

The end result is interactive conditional formatting that is dependent on the value a user selects:

See the html documentation page and the How to Change Colors and Fonts Using HTML Help Center article for more examples of Liquid interactivity for HTML.

parameter Types

Many field types can be assigned to a parameter parameter. A few special cases are detailed below.

parameters of type: string

When you use a parameter with type: string, the parameter_name._parameter_value Liquid variable requires that you enclose the values of the parameter with both single and double quotes. This is so that the single quotes are transmitted to the SQL, identifying the value as a string value. See the following example:

parameter: date_granularity { type: string allowed_value: { value: "Day" } allowed_value: { value: "Month" } } dimension: date { label_from_parameter: date_granularity sql: {% if date_granularity._parameter_value == "'Day'" %} ${created_date}::VARCHAR {% elsif date_granularity._parameter_value == "'Month'" %} ${created_month}::VARCHAR {% else %} NULL {% endif %} ;; }

In addition, if you want to include the value of a parameter with type: string in a label, you must precede the double quotes with the \ character:

label: "{% if test._parameter_value == \"'foo'\" %} 'SUCCESS' {% else %} 'FAIL' {% endif %}"

parameters of type: yesno

When you use a parameter with type: yesno, the parameter_name._parameter_value Liquid variable produces a SQL statement that evaluates to true, as appropriate for your SQL dialect. Therefore, we suggest that you do not use parameters of type: yesno in logical Liquid statements. Neither {% if yesno_parameter._parameter_value == 'Yes' %} nor {% if yesno_parameter._parameter_value %} will work properly.

parameters of type: unquoted

The unquoted type is similar to type: string, except that when the value of the parameter is inserted into the {% parameter %} Liquid variable it will not be quoted. This is useful when inserting values into SQL, such as column or table names, that cannot be quoted in order to work properly (as in the examples above).

Inserting unquoted values directly into SQL could create the possibility of unwanted SQL actions. To address this, parameter values of type: unquoted are restricted to the characters A through Z and 0 through 9 (no spaces or other special characters).

As an example, the following LookML creates a parameter named table_name that will produce an unquoted value:

parameter: table_name { type: unquoted }

Additional Resources