Parameters are dynamic values that can replace constant values in calculations, filters and reference lines.
Let’s say you want to show top product by sales. One way is to use the dimension as a filter and fix the number of products to say 10. With this solution you only show the top 10 products by sales. But what if you want to give your end user the flexibility to choose the number of products? A parameter is the solution.
Before we begin, I would like to share with you the key points to remember while working with parameters (as told to us by one of our coaches, Pete):
- Create a parameter
- Use it in either a calculated field, reference line, set or filter.
- Show the parameter control for the user
- Use the calculation in your viz
I will be using the Sample Superstore data that comes with Tableau.
- Create an Integer parameter. Set the allowable values to Range and select a minimum of 1 and a maximum of 100. Name this parameter as ‘Top N’.
2. Drag Sales to columns and Product Name to rows to create a bar chart.
3. Next, we will use this parameter in a filter as we want our user to be able choose the number of products. So, for that, control drag Product Name to filter. Navigate to the ‘Top’ tab in Filter window and select By field. To the right of ‘Top’, select your parameter ’Top N’ from the drop-down. Make sure the field to filter is chosen as Sum of Sales. Click OK
4. From the Data pane, under Parameters, right click ‘Top N’ and select Show Parameter Control.
5. You will now see a ‘Top N’ slider in the upper right corner of the worksheet. By moving the slider, the number of products shown in the worksheet will change to the number (N) selected.
6. Lastly, right click on the Product Name in rows and click Sort. Sort by field (Sum of Sales) in Descending order.
The view now shows the Top N Products (selected by parameter), sorted by sales in descending order.
Did you notice the dynamic sheet title in my worksheet? If yes, then there’s a bonus for you: How to make dynamic sheet title?
In this case we want the number of products chosen by the parameter to be shown in the title. Right click on the top left corner of the worksheet and select Edit Title. Insert ‘Parameters Top N’ from the Insert drop-down on the top right. Choose an appropriate title and click OK.
Now, every time you choose a different number using the parameter the sheet title will show the selected number for products.
WANT TO KNOW MORE?
Andy Kriebel explains when and how to use parameters through 12 use cases in this video.