Skip to Content

Dashboard filters

Filter a dashboard on an SQL expression

Use Custom LHS SQL and Custom RHS SQL to filter on an expression instead of a plain column.

A dashboard filter builds a condition: column, operator, value. With Custom SQL on, you write the two sides yourself:

<Custom LHS SQL>  <operator>  <Custom RHS SQL>
  • Custom LHS SQL (left side) takes the place of the column. It is required.
  • The operator comes from the Filter Variant: = for Single-Select, IN for Multi-Select, LIKE for Search.
  • Custom RHS SQL (right side) takes the place of the value. It is optional. Put {{global_selected_values}} where the picked value goes.

Before you start

  • You are an Admin or Editor.
  • You know the SQL dialect of your datasource.

Steps

  1. Open the dashboard and select Add filter.

  2. Fill in Step 1 of 2: Filter values and select Next. See Create a dashboard filter.

  3. In Step 2 of 2: Apply filter, set Target to Apply on.

  4. Pick the Dataset.

  5. Turn on Custom SQL.

    Apply filter step with the Custom SQL switch highlighted and on, showing the Custom LHS SQL and Custom RHS SQL editors.
    Custom SQL is under the column picker; it swaps the column for two SQL boxes.
  6. In Custom LHS SQL, enter the expression, for example LOWER(customers.region).

    Custom LHS SQL editor highlighted with LOWER of the store state column typed in it.
    Custom LHS SQL takes the place of the column.
  7. Optional: in Custom RHS SQL, enter the value side, for example LOWER({{global_selected_values}}).

    Custom RHS SQL editor highlighted with LOWER({{global_selected_values}}) typed in it.
    Custom RHS SQL takes the place of the value.
  8. Select Save.

With those two values, a viewer who picks West gets this condition:

LOWER(customers.region) = LOWER('West')

How values are put in

  • Single-Select: {{global_selected_values}} becomes one quoted value, for example 'West'.
  • Multi-Select: it becomes a list, for example ('West', 'East'). If nothing is picked, the condition is 1 = 0 and no rows match.
  • No RHS: the picked value is used as it is.
  • null: a picked null becomes IS NULL.

Databrain quotes and escapes every value. A viewer’s value is never run as SQL.

If something goes wrong

  • No rows match. Test the expression in your datasource with a known value, then check the quotes in your RHS.

To put a value inside the metric SQL instead, see Pass a dashboard filter into metric SQL.