KNOWLEDGE BASE

Dynamically Filtering Views with String Parameters


Published: 27 Sep 2013
Last Modified Date: 09 Aug 2017

Question

How to use a parameter to search a field for a string value.

Environment

Tableau Desktop

Answer

Filters allow you to easily remove data from the view and focus on just the information you need. When you are building a more complicated view or dashboard, you may find that you have added lots of filters to help people narrow down a large view to a specific set of data such as a single region or product. In that case, the filter controls can sometimes take up a lot of space and take attention away from the data in the view. To avoid that, you can create a sort of Type In parameter that accepts values for multiple fields and then filters based on what you typed in.

The following examples will show different methods to achieve this goal. 

CLICK TO EXPAND SOLUTION
Example 1: Filter Option - single field (view interaction)

The below steps can be reviewed in the attached workbook DynamicStringSearch.twbx.  

Create the Parameter

  1. Open Tableau Desktop and connect to Superstore sample data.
  2. Right-click in the Data window and then select Create Parameter.
  3. In the Create Parameter dialog box, do the following, and then click OK:
    • Name the parameter. In the example workbook, the parameter is named Search States.
    • For Data Type, select String.
    • For Current value, type a.
    • For Allowable values, select All.
  4. Right-click the parameter and then select Show Parameter Control.

Create the Calculated Field

  1. Select Analysis > Create Calculated Field
  2. In the Calculated Field dialog box that opens, name the calculated field Contains States
  3. Enter the following formula and then click OK:
  4. CONTAINS([State],[Search States] 
  5. Right-click the parameter and then select Show Parameter Control.

Create the View

  1. Drag Category to Columns.
  2. Drag Sales to Rows.
  3. Drag Category to Color.
  4. Drag State to Detail.
  5. Drag Contains States to Filters.
  6. Select True, and then click OK.
To view the steps showed in the below video, please expand the above section.
Note: the video has no sound.
 
CLICK TO EXPAND SOLUTION
Example 2: Filter Option - multiple fields (view interaction)

The below steps can be reviewed in the attached workbook DynamicStringSearch.twbx

Create the Parameter

  1. Open Tableau Desktop and connect to Superstore sample data.
  2. Right-click in the Data window and then select Create Parameter.
  3. In the Create Parameter dialog box, do the following, and then click OK:
    • Name the parameter. In the example workbook, the parameter is named Type String to filter.
    • For Data Type, select String.
    • For Current value, type a.
    • For Allowable values, select All.
  4. Right-click the parameter and then select Show Parameter Control.

Create the Calculated Field

  1. Select Analysis > Create Calculated Field
  2. In the Calculated Field dialog box that opens, name the calculated field Show
  3. Enter the following formula and then click OK:
  4. CONTAINS([State],[Type String to Filter]) OR CONTAINS([Category],[Type String to Filter]) OR CONTAINS([Region],[Type String to Filter]) 

Create the View

  1. Drag Sales to Columns.
  2. Drag Region and Customer Names to Rows.
  3. Drag Category to Color.
  4. Drag State and Sub-Category to Detail.
  5. Drag Show to Filters.
  6. Select True, and then click OK.
To view the steps showed in the below video, please expand the above section.
Note: the video has no sound.
CLICK TO EXPAND SOLUTION
Example 3: Display a specific string (no view interaction)

The below steps can be reviewed in the attached workbook DynamicStringSearch.twbx.

Create the Calculated Field

  1. Select Analysis > Create Calculated Field
  2. In the Calculated Field dialog box that opens, name the calculated field Search specific product
  3. Enter the following formula and then click OK:
  4. Contains([Product Name], "Belkin") 
  5. Right-click the parameter and then select Show Parameter Control.

Create the View

  1. Drag Sales to Columns.
  2. Drag Category, Sub-Category and Product Name to Rows.
  3. Drag Category to Color.
  4. Drag State to Detail.
  5. Drag Search specific product to Filters.
  6. Select True, and then click OK.
To view the steps showed in the below video, please expand the above section.
Note: the video has no sound.

Additional Information

Learn more about this topic by watching the On-Demand free training video: String Calculations.

When dragging the calculated field on the Filter shelf, you may only see a check box for "Hide" depending on what you made your initial value for your parameter.

  • For example, if you made it "None", there are no records where Region or Department or States match the word, "None."
  • If you do not see a check box for "Hide", select the "Custom Value List" radio button. Then manually type in the word "Show" and click the plus button to add it to the list.
Did this article resolve the issue?