Two powerful features of Tableau are the ability to link data from different data connections together on one dashboard, and to filter data in multiple views at once. However, by default, filters apply to views from only a single data source. If your view blends data from multiple data sources, you might want a way to filter views that contain fields from multiple sources.
This article shows two ways to filter across multiple data sources, using sample data sources that come with Tableau Desktop.
- Create a custom parameter and use it in a calculated field.
- Create a list box view for the field you want to filter on, and apply a filter action to that view on the dashboard.
Note: This article assumes that you are already familiar with the concepts of filters and data blending. To learn more, see the topics under Working With Multiple Connections in the Tableau Desktop Help.
Prepare views for sample filtering exercises
The steps in the remaining sections of this article build from the example dashboard shown in the following image.
The top view shows the Superstore’s monthly sales figures by department. The bottom view compares the Coffee Chain’s monthly sales and profits. Each the view is from a different data source, and you will filter both of them simultaneously by state.
To prepare for the steps, you can create two similar views, one using Superstore data, and the other using Coffee Chain. Then create a dashboard with the two views.
You can use the Sample – Superstore data source that comes with Tableau Desktop, and the Sample – Coffee Chaindata source provided with this article. For the Coffee Chain data source, you must be running Tableau Desktop on a Windows computer.
Note: It’s not important that the views look exactly as the ones in the example. However, the steps will be easier to follow if you use the same data sources and each source's State field.
Create a parameter and a calculated field
The following steps describe how to create a new parameter, and then use it in a calculated field to filter on State.
Step 1
With your workbook open and displaying any worksheet, right-click an empty area in the Data pane and select Create Parameter.
Step 2
In the Create Parameter dialog box, complete the following steps:
- For Name, type Select State.
- For Data Type, select String.
- For Allowable Values, select List.
- Under List of Values, select Add from Field >
> State.In this example, Coffee Chain is the first data source. - Click OK.
Step 3
With the Coffee Chain data source selected in the Data window, select Analysis > Create Calculated Field.
Step 4
In the Calculated Field dialog box, complete the following steps.
- For Name, type State Filter.
- In the Formula box, build the following formula:
[Select State]=[State]
- Confirm that the formula is valid, and then click OK.
This calculation checks whether the state selected in the parameter matches the state field in your data source, and then returns true or false.
Step 5
Using the Superstore data source displayed in the Data window, repeat steps 3 and 4, above to create the same calculated field in this data source (you do not need to recreate the Select State parameter).
Create the view using the parameter
Step 1
In your sample workbook, display the worksheet that uses Superstore as the primary data source.
Step 2
From the Dimensions pane, drag State Filter to the Filters card, and in the Filter dialog box, select True, and then click OK.
Step 3
Display a worksheet that uses Coffee Chain as the primary data source, and repeat the previous step with the State Filterfield in this worksheet.
Step 4
Display your dashboard that includes views from both data sources, and add the parameter control.
From the drop-down menu for one of the views, select Parameters > Select State.
Step 5
Select a state from the parameter control. Views that use either or both data sources refresh to show data from the selected state.
Use a dashboard filter action on a control view
In this example, to use filter actions on views that use data from multiple sources, you add a third view that shows a list of the values in the field that you want to filter on, in this case State.
This third view serves as the filter control. When you select a state in the list, , it updates the other views to show data only for that state.
Step 1
If you are continuing from the previous section, in which you created a parameter and calculated field, reset the workbook by doing the following:
- In each view, remove the State Filter parameter from the Filters card.
- On the dashboard, remove the parameter control.
Step 2
To create the filter control view, follow the steps in the Knowledge Base article Creating Filters with Actions on Dashboards, using the State field instead of the Category field.
When you are finished, your dashboard should look similar to the following image.
Step 3
With the dashboard displayed, select the list box view you created, and from the drop-down menu in the upper-right of the view, select Use As Filter.
Step 4
Select Dashboard > Actions, and in the Actions dialog box, select the generated filter action, and click Edit.
Step 5
In the Edit Filter Action dialog box, complete the following steps:
- For Name, type Filter both views.
- Under Source Sheets, select the state-list (control) view and run the action on Select.
- Under Target Sheets, select the views that will be filtered when you click a state in the list. For Clearing the selection will, select Show all values.
- Click OK.
Notes
For this to work, the field you use as a filter must exist in both data sources. In this case, the State field is in both the Superstore and Coffee Chain tables.
In your own data sources, if the fields hold the same data but are named differently, under Target Filters, you can selectSelected Fields and click Add Filter to map the fields.
Step 6
Back on the dashboard, select a state in the list view filter to see the other two views update simultaneously.