Parameters are mostly useful when you want to add interactivity and flexibility to a report or experiment with what-if scenarios. Suppose you are unsure about which fields to include in your view or which layout would work best for your viewers. You can then incorporate parameters into your view to let viewers choose how they want to look at the data.
Before beginning, decide which fields you want to make interactive. For example, you can allow users to view the categories within a dimension by color, view sales data over a period they choose, etc. The example described below sets up a table for which users could select the dimensions to display in the columns and rows.
How to Create Parameters?
The below steps use the Superstore sample to create new parameters.
Step 1: In the Data pane, click the drop-down arrow in the upper right corner and select Create Parameter.
Step 2: In the Create Parameter dialog box, perform the following steps:
- Name the parameter so that the viewers can tell what changes it will do. This example is using Select Column 1 Heading.
- For Data type, select option String.
- For Allowable Values, select option List, type None as the first value in the list and then press Enter.
- Complete the list by typing the additional dimension fields’ names that you want to expose through the parameter.
The Display As aliases defaults the field name, and for this step, you can leave them as they are.
- Click OK to return to the dialog box Calculated Field.
Step 3: Repeat the previous step to create the following additional parameters:
- Select Column 2 Heading
- Select Row 1 Heading
- Select Row 2 Heading
Create the calculated fields:
The below steps use the Superstore sample to build the calculated fields to take advantage of your parameters.
Step 1: In the Data pane, click the drop-down arrow in the upper right corner and select Create Calculated Field.
Step 2: In the dialog box, Calculated Field, for Name, type Column 1 Category.
Step 3: In the Calculated Field dialog box, for Formula, add the following calculation:
CASE [Select Column 1 Heading] WHEN 'Customer Name' THEN [Customer Name] WHEN 'Customer Segment' THEN [Customer Segment] WHEN 'Region' THEN [Region] WHEN 'Department' THEN [Department] WHEN 'Category' THEN [Category] ELSE '' END
Confirm that the status message represents that the formula is valid, and then click on OK.
Step 4: Create three more calculated fields, one for each of the additional parameters you created:
The basic formula for the calculated field is the same as done in the previous step, except you refer to a different parameter in each CASE statement.
How to allow viewers to interact with views?
Next, expose the parameter control so that the users can select the categories they want to display.
Step 1: For each parameter, you have created, do the following:
Under Parameters, right-click on the parameter and select Show Parameter Control.
Step 2: From the Data pane, drag the calculated fields you created to the Columns and Rows shelves.
Step 3: From the Data pane, drag a measure to the view. In this example, Sales are placed on Label on the Marks card.
Step 4: Test your parameters by selecting the fields in the parameter controls.
Tips:
- Sort the dynamic dimension fields in alphabetical order.
- Hide the field labels for rows and columns.
Step 5: Reset all parameters to None and publish the workbook to Tableau Server.
Viewers can set up their reports, save their parameter settings, and share views with others.