Menu Close Get Metabase

Cross-filtering: using a chart to update a dashboard filter

Oct 30, 2020 by The Metabase Team

Metabase allows you to customize what happens when you click on a question card in a dashboard. This article will walk through how to set up cards to update dashboard filters - what we call cross-filtering.

Here’s the dashboard we’re going to wire up:

<em>Fig. 1</em>. Our starter dashboard that with cards about Orders from the Sample Dataset included with Metabase..
Fig. 1. Our starter dashboard that with cards about Orders from the Sample Dataset included with Metabase..

This Cross-filtering dashboard shows information about orders in the Sample Dataset included with your Metabase installation.

Here’s our goal: we want to set up this dashboard so that when people click on a state in the map, the dashboard’s State filter updates and filters every other card except the Orders by state card.

We also want to wire up the dashboard so that when people click on a category in the bar chart, the category filter updates, and all the cards except the Orders by product category card update to filter orders by that category.

Here’s the finished dashboard in action:

<em>Fig. 2</em>. Clicking on Wisconsin updates the state filter, filtering the dashboard for orders placed from users in Wisconsin. Clicking on Gadget or Widget updates the Category filter, and filters the dashboard for orders with products in those categories.
Fig. 2. Clicking on Wisconsin updates the state filter, filtering the dashboard for orders placed from users in Wisconsin. Clicking on Gadget or Widget updates the Category filter, and filters the dashboard for orders with products in those categories.

Setting up the filters

We’ve already added questions related to orders to our dashboard, so we’ll start by adding two filters: a State filter and a Category filter. The setup process for both filters is similar, so we’ll focus on adding the State filter and you’ll get the idea.

From the dashboard, we’ll click on the pencil icon to enter dashboard editing mode. To add a state filter, we’ll select the filter icon from the menu on the top right. For filter type, we’ll select Location, and for kind, we’ll select State. To learn more about setting up filters, see Dashboard filters.

<em>Fig. 3</em>. Add a Location filter.
Fig. 3. Add a Location filter.

Next, we’ll want to wire up every card to our state filter except the card we want to use to update that filter: the Orders by state card. This way, we can click on different states, and the other cards will update to show orders from users in the clicked state.

To set up this cross-filtering, let’s set every other card’s Column to filter on to User.State.

<em>Fig. 4</em>. Connect each card to the <strong>State</strong> filter <em>except</em> the <strong>Orders by state</strong> card, as we want to use the state map to update the <strong>State</strong> filter.
Fig. 4. Connect each card to the State filter except the Orders by state card, as we want to use the state map to update the State filter.

Next, we’ll want to set up the map of the United States to update the state filter on click. To do that, we’ll need to change the click behavior for our Orders by state question. Hover over the Orders by state card and click on the Click behavior icon (figure 5):

<em>Fig. 5</em>. Hover over the Orders by state card and select the <strong>Click behavior</strong> icon.
Fig. 5. Hover over the Orders by state card and select the Click behavior icon.

Metabase will slide out a sidebar where we can define what happens when people click on the Orders by state cards. Since we want the card to update the State filter, we’ll select the Update a dashboard filter option.

<em>Fig. 6</em>. For <strong>Click behavior for Orders by state</strong>, select <strong>Update a dashboard filter</strong>.
Fig. 6. For Click behavior for Orders by state, select Update a dashboard filter.

Metabase will list the dashboard’s available filters that we can update:

<em>Fig. 7</em>. Metabase will list the available filters to update on click.
Fig. 7. Metabase will list the available filters to update on click.

Since we want to update the State filter, we’ll select the State filter, and pass the value of User->State to the filter.

<em>Fig. 8</em>. We'll need to select a column to specify which value we want to send to the filter. In this case, we pass <strong>User->State</strong>.
Fig. 8. We'll need to select a column to specify which value we want to send to the filter. In this case, we pass User->State.

With that: Metabase will give us a summary of the click behavior we just defined. In this case, we’ve set up the Orders by state card to update the State filter by passing the value User-State to the filter.

<em>Fig. 9</em>. Metabase will summarize our configured click behavior: the Orders by state card will update a dashboard filter by passing the value from the <strong>User->State</strong> column to the dashboard's State filter.
Fig. 9. Metabase will summarize our configured click behavior: the Orders by state card will update a dashboard filter by passing the value from the User->State column to the dashboard's State filter.

Let’s Save our changes, and try out the new click behavior:

<em>Fig. 10</em>. Clicking on a state once filters the rest of the cards by that state. Clicking on the state a second time resets the filter.
Fig. 10. Clicking on a state once filters the rest of the cards by that state. Clicking on the state a second time resets the filter.

In figure 10 above, if we click on Wisconsin, the dashboard will filter the other cards for orders by users from Wisconsin. If we click on Wisconsin again, the filter resets, and the other cards on the dashboard update to show all orders from all states.

So far so good. Now let’s move on to set up the Orders by product category to update the dashboard’s Category filter.

The process is more or less the same as above, so we won’t walk through it step by step. All we need to do is:

  • Add a Category filter to filter the dashboard by Product->Category.
  • Wire up every card except Orders by product category to the dashboard’s category filter.
  • Set the click behavior on Orders by product category to update the Category filter by passing values from the Product->Category column.

The sidebar will show a summary of our configured click behavior:

<em>Fig. 11</em>. Summary of click behavior for <strong>Orders by product category</strong>: update the dashboard's Category filter by passing values from the <strong>Product->Category</strong> column.
Fig. 11. Summary of click behavior for Orders by product category: update the dashboard's Category filter by passing values from the Product->Category column.

Let’s Save our changes, and we’re done. We have a dashboard that people can cross-filter by state or category simply by clicking on a chart:

<em>Fig. 12</em>. Summary of click behavior for <strong>Orders by product category</strong>: update the dashboard's Category filter by passing values from the <strong>Product->Category</strong> column.
Fig. 12. Summary of click behavior for Orders by product category: update the dashboard's Category filter by passing values from the Product->Category column.

In our example, we added text cards to let people know they can click on a chart to filter the dashboard, but you might want to just let people discover this cross-filtering functionality on their own. And if they miss it, they can always update the filter widgets by manually plugging in the values.

Happy cross-filtering!

Further Reading

For more about customizing click behavior, check out our post on custom destinations, which covers how to set up dashboard cards to link to other dashboards, saved questions, and even external URLs, allowing you to create rich clickpaths through your data.

Here are some additional links that cover working with filters in Metabase: