Skip to Content

Metric filters

Use a metric filter as a SQL variable

Put the value a viewer picks into a placeholder in your metric's SQL.

Put the value a viewer picks into a placeholder in your metric’s SQL.

Before you start

Steps

  1. In Query editor, add a placeholder in double curly braces, for example:

    SELECT * FROM orders WHERE 1=1 [[ AND status IN {{status_variable}} ]]
    Query editor highlighted with a query whose optional WHERE part holds the placeholder state_variable in double curly braces.
    Put the placeholder in double curly braces inside the query.
  2. Run the query and select Use results.

  3. Above the chart, select Add filter, then Metric Filters.

  4. Enter a Filter Name and set the options, for example Manual with Multi-Select. Apply a metric filter

  5. Select Next.

  6. Of the two tabs, Apply On and Variable Filter, select Variable Filter.

    Metric Filters dialog second step with the Variable Filter tab highlighted next to Apply On.
    Variable Filter is the second tab of the second step.
  7. In Variable Value, enter the placeholder name, for example status_variable.

    Metric Filters dialog with state_variable typed in the highlighted Variable Value field and the placeholder shown below it.
    Enter the placeholder name; the line under it shows it in braces.
  8. Select Save.

Under the field, the form shows the placeholder as {{status_variable}}. When a viewer picks values, Databrain puts them into the query in its place.

How the value goes in

  • Single-Select puts in one value. Text values get quotes. Write status = {{status_variable}}.
  • Multi-Select puts in a list. Write status IN {{status_variable}}.
  • Range and Date ranges ask for two names, From and To, for example WHERE amount BETWEEN {{min_amount}} AND {{max_amount}}.
  • Wrap a condition in [[ ]] to drop it when the viewer picks nothing. Without a value, the example above runs without the status condition.

In Python mode, Variable Filter is the only target.

If something goes wrong

  • The filter has no effect. Check that the name in Variable Value matches the placeholder in the SQL exactly.