> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usedatabrain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dashboard Filter

> In this page we will explain you how you can create filters for the dashboard metrics

### Creating a Dashboard Filter in DataBrain

To add a dashboard filter, click on the **"+"** sign located below the dashboard's name. Start by selecting the datatype for the filter, which will influence the available filter option types—auto, manual, or custom. Note that the option type may vary based on the selected datatype.

#### Customizations Based on Datatype:

* **Filter Variant**: Choose between single select, multi-select, or search options for how users can interact with the filter.
* **Select Default Value**: Automatically select a default value or allow users to choose one. This setting depends on the datatype.
* **Scope to Client**: Filter options will be tailored based on the client. This ensures that filter choices are relevant to a specific client’s data context.
* **Label Column Setup**: Configure a label column that displays descriptive labels for the values being filtered. This enhances readability and user understanding of what each filter value represents.

***

### Dependent Filters

Use dependent filters when the available options in one filter should be constrained by the selection in another filter (for example, **Store City** depending on **Store State**).

#### Columns from Same Table

Create two filters (**Store State** and **Store City**) on the same dataset, and configure **Store City** to depend on **Store State**.

**Store State**

<Frame>
  <img src="https://mintcdn.com/databrainlabs-bef6850a/7llrRlNKuslfkyn6/images/guides/store-state.png?fit=max&auto=format&n=7llrRlNKuslfkyn6&q=85&s=01b22753aeb688c3ddb87a3a0ab816e5" alt="Dashboard Filters configuration for Store State filter using the main.demo_sales dataset" width="1526" height="1166" data-path="images/guides/store-state.png" />
</Frame>

**Store City depends on Store State**

<Frame>
  <img src="https://mintcdn.com/databrainlabs-bef6850a/7llrRlNKuslfkyn6/images/guides/store-city.gif?s=44b9ff5a679c62790e7be583f7ae4e90" alt="Dashboard Filters configuration for Store City filter with dependency on Store State" width="1394" height="1075" data-path="images/guides/store-city.gif" />
</Frame>

#### Columns from Different Tables

When the top-level and dependent filters use columns from different tables, configure the dependency using a custom SQL query that joins the tables.

**Step 1: Configure the Top-Level Filter**

Set up the first-level filter as you normally would.

<Frame>
  <img src="https://mintcdn.com/databrainlabs-bef6850a/jjGr9LegR2IqJe8O/images/guides/level1.png?fit=max&auto=format&n=jjGr9LegR2IqJe8O&q=85&s=36489e396da93922581fbc482a3ba017" alt="Dashboard Filters configuration for Level 1 filter on the coffees dataset" width="1526" height="1174" data-path="images/guides/level1.png" />
</Frame>

**Step 2: Configure the Dependent (Second-Level) Filter**

For the second-level filter (which needs to depend on the first filter), select **Custom** as the filter type and write the SQL in the following format:

```sql theme={"dark"}
SELECT
  Concat_ws(
    ' ',
    "main_customers"."first_name",
    "main_customers"."last_name"
  ) AS "name",    /* Label for this filter */
  "main_customers"."customer_id" AS "customer_id", /* Column for this filter */
  "main_coffees"."coffee_id" AS "coffee_id"       /* Connecting column between Level 1 and Level 2 */
```

```sql theme={"dark"}
FROM
  "main"."coffees" AS "main_coffees"
  INNER JOIN "main"."orders" AS "main_orders"
    ON "main_coffees"."coffee_id" = "main_orders"."coffee_id"
  INNER JOIN "main"."customers" AS "main_customers"
    ON "main_orders"."customer_id" = "main_customers"."customer_id"
```

<Note>
  Make sure the query includes the <strong>connecting column</strong> between Level 1 and Level 2.
</Note>

The necessary joins are added to establish the relationship between the two filter tables.

**Step 3: Configure Dependency**

In the filter setup, you will see that the column from Level 1 is part of the above query.

* In **Advanced Options**, under **Depend On**, type the connecting column from Filter 1 to ensure linkage.

This ensures that Filter 2 is correctly dependent on Filter 1.

<Frame>
  <img src="https://mintcdn.com/databrainlabs-bef6850a/Y_Qmu5yObO4cFtUL/images/guides/depend-on.png?fit=max&auto=format&n=Y_Qmu5yObO4cFtUL&q=85&s=8abf62902e096c5c43cde0620113ccec" alt="Dashboard Filters configuration showing Depend On section linking the second-level filter to the first-level filter via the connecting column" width="1472" height="1821" data-path="images/guides/depend-on.png" />
</Frame>

***

#### Applying the Filter:

Once the filter settings are configured, decide where to apply these filters within the dashboard:

* **Direct Apply**: Immediately apply the filter to the dashboard elements.
* **Variable for Custom SQL**: Obtain a variable that can be used in your custom SQL queries, allowing for more tailored data interactions.

For a detailed guide on Variable Apply On, kindly refer the below link:

<Card title="Dashboard Filter - Variable Apply On" href="https://docs.usedatabrain.com/guides/dashboards/create-modify-dashboard-filter/dashboard-filter-variable-apply-on">
  View detailed guide on how to use Variable Apply On for filters.
</Card>

* **Custom SQL**: Directly write the left-hand side (LHS) equals the right-hand side (RHS) condition in the WHERE clause of your SQL query.

After setting up the filters and their application, click 'Save' to finalize and activate them on the dashboard. This process enhances data interaction, making your dashboard more dynamic and suited to specific analytical needs.
