Menu Close Log in Get started

Lesson

Linking filters in dashboards

Link filters in dashboards to limit the choices available in one filter based on the current selection of another filter.

Metabase lets you link filters on dashboards so that the value plugged into one filter limits the options available to the linked filters.

We’ll start by setting up a simple dashboard with a few questions before we start linking filters. If you already have a dashboard with a filter to work with, feel free to skip ahead.

Setting up a dashboard, adding saved questions, and adding a dashboard filter

Let’s begin our example using the Sample Database included with Metabase. For more detailed tutorials on asking questions and creating dashboards, check out the Getting Started track.

We’ll need a new dashboard before we go any further. If you aren’t sure how to make one, our documentation covers that.

We also need a few questions to populate this shiny new dashboard. Let’s ask the following three questions about orders and the people who place them:

  1. How many orders are there?: Start with a simple question, choose the Orders table as your data, and summarize by count of rows.

  2. How many orders did we receive each month?: Pick the Orders table again to start, and then summarize that table by count of rows and group by Created At by month.

  3. Where are our customers located?: Use the People table as your starting data, and select the Map visualization to generate a pin map.

If you get stuck, our documentation covers how to ask questions like these. Be sure to save each question and add them to the new dashboard. You can adjust the size and placement of each card on the dashboard however you like best; it’ll end up looking something like Figure 1.

<em>Fig. 1</em>. Example dashboard before adding a filter or saving.
Fig. 1. Example dashboard before adding a filter or saving.

Finally, we’ll need a dashboard filter that lets us see orders from different states depending on which value we input. While editing the dashboard, click the filter icon to add a filter for our dashboard. This a filter that we can apply to all three of our dashboard cards — different from filtering an individual question. We want to add a Location filter, by State, and will need to connect each of the dashboard cards to the new filter by selecting State from each card’s dropdown menu. Click Done to add the filter, and Save the dashboard.

One thing to call out is that we connected the State filter to multiple different state columns and it just works. In this dashboard, we’ve connected the State filter to two cards by filtering on the column User.State, but the People map card filters on Person.State. If we plug a value into the State filter, say WI for Wisconsin, the dashboard will update all three cards to display only the orders placed by people who live in the state of Wisconsin:

<em>Fig. 2</em>. The same dashboard as in figure 1, filtered by the state of Wisconsin.
Fig. 2. The same dashboard as in figure 1, filtered by the state of Wisconsin.

Example of a linked filter

To link filters, we’re going to need another filter. So let’s say we want to add a filter to the dashboard for cities. On the dashboard, we’ll click on the pencil icon to enter dashboard edit mode, then click on the filter icon to add a new filter.

For What do you want to filter?, we’ll select Location. For What kind of filter?, we’ll select City.

With our City filter created, we can now wire it up by connecting each card to the filter. To do that, we select which column we want to filter by, which in our case is Person.City or User.City, depending on the card.

<em>Fig. 3</em>. Connecting each card to the <strong>City</strong> filter.
Fig. 3. Connecting each card to the City filter.

Once we’ve connected our cards to the new City filter, we’ll save our changes.

And here’s where we’ll run into an issue. Right now, the filters are independent of each other. So the State filter will let us pick a state, say Wisconsin, and the City filter will let us select any city - including cities outside of Wisconsin. Basically, this dashboard will let us set up nonsensical filter combinations, like filtering for the city of Austin in the state of Wisconsin, which is not how our universe is currently set up. As expected, this combo of filters yields no results:

<em>Fig. 4</em>. Nonsensical filter combinations yield no results: Austin is not a city in Wisconsin.
Fig. 4. Nonsensical filter combinations yield no results: Austin is not a city in Wisconsin.

We can prevent people from creating these nonsensical filter combos by linking the filters. For example, if someone chooses Wisconsin in the State filter, the City filter should “know” to limit the options for cities to only those within the state of Wisconsin.

To link the two filters, we’ll click on the pencil icon to return to dashboard edit mode. Since we want the City filter to react to a change in the State filter, we’ll want to change the settings on the City filter. We’ll click the gears icon on the City filter to bring up the settings sidebar for the City filter.

Here’s the important part: in the sidebar, we’ll click on the Linked filters tab, which presents us with options to limit this filter’s choices, i.e., the City filter’s choices.

Metabase will list the available filters that we can link the City filter to (figure 5). In this case, there’s only one filter, the State filter, so we’ll toggle that filter on to link the filter.

<em>Fig. 5</em>. Limit the City filters choices based on values selected for the State filter.
Fig. 5. Limit the City filters choices based on values selected for the State filter.

Let’s save our changes, and try it out.

With the City filter linked to the State filter, when we plug in WI for the state filter, we’ll see that the City filter now knows to only show cities in Wisconsin.

<em>Fig. 6</em>. Linked filters: the City filter knows to limit its choices based on the linked State filter's value.
Fig. 6. Linked filters: the City filter knows to limit its choices based on the linked State filter's value.

Further reading

Here are some more articles that cover working with filters:

You can also check out our documentation on Dashboard Filters.

Thanks for your feedback!

Get articles like this one in your inbox every month