KNOWLEDGE BASE

Swapping Filters Using a Parameter


Published: 07 Apr 2017
Last Modified Date: 24 Jul 2017

Question

How to filter the view differently based on a parameter value.

For example, swapping between filtering the view to see sales for this month or sales that were over $1000.

Environment

Tableau Desktop

Answer

The attached example workbook uses the sample data set Superstore to demonstrate the following directions:

Step 1: Create a Parameter

  1. Click the down arrow next to Dimensions in the data pane and select Create Parameter…
  2. In the Create Parameter dialog, do the following and click OK:
    1. Name the parameter. In this example I will call it "Choose a filter"
    2. For Data Type, choose String
    3. For Allowable values, select List
    4. Add two options to the list for "sales this month" and "sales over $1000"
  3. Right-click [Choose a filter] in the data pane and select Show Parameter Control.

Step 2: Create the following Calculated fields

  • Select Analysis > Create Calculated Field...
  • Create a Calculated Field called "Sales this month filter" using the following formula:
    DATETRUNC( 'month', [Order Date] ) = DATETRUNC( 'month', TODAY() )
  • Select Analysis > Create Calculated Field...
  • Create a Calculated Field called "Sales over $1000" using the following formula:
    [Sales] > 1000
NOTE: for this example, the calculated fields for the separate filters must return TRUE or FALSE 
  • Select Analysis > Create Calculated Field...
  • Create a Calculated Field called "Swap Filter" using the following formula:
    ( [Choose a filter] = "sales this month" AND [Sales this month] )
    OR
    ( [Choose a filter] = "sales over $1000" AND [Sales over $1000])
NOTE: for this example, the calculated fields for the separate filters must return TRUE or FALSE 

Step 3: Enable the Swap Filter calculated field

  1. Drag [Swap Filter] to the Filters shelf.
  2. In the Filter dialog, check True and click OK.
Did this article resolve the issue?