KNOWLEDGE BASE

Filtering Data With a Parameter


Published: 08 Sep 2014
Last Modified Date: 17 Apr 2023

Question

How to filter data utilizing a parameter.

Environment

Tableau Desktop

Answer

Parameters cannot be used directly in the view, and instead need to be added to a dimension filter or a calculated field.

Option 1: Add parameter to dimension filter

A numeric parameter can be used in the Top tab of a dimension filter. See Using a Top N Parameter to Filter a Table for directions.
 

Option 2: Create calculated field referencing parameter

The example workbook, available for download in the right-hand pane of this article, uses the sample data set Superstore to demonstrate the filtering a bar chart of sales by state to a region selected in a parameter. 
 
Step 1: Creating the parameter
  1. Right-click in the data pane and select Create Parameter....
  2. In the dialog box, name the parameter. In this example, the parameter is named "Region Parameter". 
  3. Under Data type select String.
  4. Under Allowable values select List.
  5. Click Add from Field > Region.
  6. Add an additional value of All with the display text of All.
  7. Click OK.
Step 2: Creating the calculated field
  1. Select Analysis > Create Calculated Field
  2. In the Calculated Field dialog box that opens, do the following, and then click OK:
    1. Name the calculated field. In this example, the calculated field is named "Region Parameter Filter"
    2. In the formula field, create a calculation similar to the following:
      [Region Parameter] = [Region]
      OR [Region Parameter] = "All"
      

Step 3: Creating the view

  1. Drag [Sales] to the columns shelf
  2. Drag [State/Province] to the Rows shelf 
  3. Right-click on [Region Parameter] in the data pane and select Show Parameter Control
  4. Drag [Region Parameter Filter] to the Filters shelf
  5. In the Filter dialog, check True and click OK

 

Additional Examples

Parameters can be strings, like above, or can be numeric, Boolean, or date values. The following example calculations cover these different data types. All examples are demonstrated in the attached example workbook.
Numeric Parameter
SUM( [Sales] ) >= [Sales Parameter]
Boolean Parameter
SUM( [Sales] ) >= 100000
OR NOT [Show Only High Sales Parameter]

This calculation will return True when SUM([Sales]) is above 100,000 or if False is selected in [Show Only High Sales Parameter]. The operator NOT converts False into True, and when a value is selected in a parameter then that value applies for every record in the data set.

Date parameter
[Order Date] >= [Start Date Parameter]
AND [Order Date] <= [End Date Parameter]

Additional Information

The example calculated fields above all return True or False, but any calculated field referencing a parameter can be used as a filter.

 
Did this article resolve the issue?