Friday, July 8, 2016

Changing Views Using Parameters


These steps use the Superstore sample to create a new parameter while you build the calculated field that will take advantage of it.
Step 1
Select Analysis > Create Calculated Field.
Step 2
In the Calculated Field dialog box, for Name, type Column 1 Category.
Step 3
Next to Parameters, click Create, and in the Create Parameter dialog box, complete the following steps.
  1. Name the parameter appropriately so that viewers can tell what changing it will do. This example uses Select Column 1 Heading.
  2. For Data type, select String.
  3. For Allowable Values, select List, type None as the first value in the list, and then press Enter.
  4. Complete the list by typing the names of the additional dimension fields that you want to expose through the parameter.Note: This example uses the customer name, customer segment, region, department, and category fields. These are all dimensions of the same data type (string). If you wanted to include a measure such as profit in this list, one option would be to convert the measure to a string value. You would do this when you build the calculated field, using the STR() function. This article covers only the single data type scenario.
  5. The Display As aliases default to the field name, and for this exercise you can leave them as they are.
  6. Click OK to return to the Calculated Field dialog box.
Step 4
Repeat the previous step to create the following additional parameters:
  • Select Column 2 Heading
  • Select Row 1 Heading
  • Select Row 2 Heading
Tip: Instead of typing each value in the list, click Add from Parameter to add them from Select Column 1 Heading.
Step 5
In the Calculated Field dialog box, for Formula, build the following calculation:
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 indicates that the formula is valid, and then click OK.
Note: ELSE accounts for the None value that you included in the parameter, and it returns an empty string.
Step 6
Create three more calculated fields, one for each of the additional parameters you created:
Parameter name
Calculated field name
Select Column 2 Heading
Column 2 Category
Select Row 1 Heading
Row 1 Category
Select Row 2 Heading
Row 2 Category
The basic formula for each calculated field is the same as in the previous step, except that you reference a different parameter in each CASE statement.
Give viewers a way to interact with views
Now you expose the parameter control so users can select the categories they want to display.
Step 1
For each parameter you created, do the following:
In the Parameters pane, right-click the parameter and select Show Parameter Control.
Step 2
From the Dimensions pane, drag the calculated fields you created to the Columns and Rows shelves.
Step 3
From the Measures pane, drag a measure to the view. In this example, Sales is placed on Label on the Marks card.
Step 4
Test your parameters by selecting fields in the parameter controls.
Tips:
  • Sort the dynamic dimension fields alphabetically.
  • Hide 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 own reports, save their parameter settings, and share views with others.

No comments:

Post a Comment