Being able to create custom calculations is a very useful functionality of any tool. It gives the user an immense flexibility and power to do a lot of things. However, there are times when we would want to go beyond the calculations that are based on static hard coded conditions. So, for example, in the Logic statement that we saw earlier, we had hard coded the Sales Target value to 100K. Now the problem is that as we continue with our business, the 100K target may soon become redundant and the calculations will soon have to be revisited. Plus, hard coding the Target at the development stage may not be a good idea as the end user may have some different values in mind. In this case, it makes sense to have the option where, the end user can pass certain values at the viewing level.
To address the preceding requirement, we will use the parameter functionality provided by Tableau. Parameters are controls that can be given to the end user to dynamically modify values and/or replace the constant values in calculations. Thus, rather than manually editing the calculation and all its dependent calculations, we can use a parameter, which will ensure that when we select or enter the value in the parameter, all the calculations that are using the parameter will update accordingly.
Now that we have understood what Parameters are, let us explore them in detail and see how we can create and use them.
Let us see how to create and use parameters in the following recipe. We will continue with our existing Sample - Superstore.xlsx
data source. Let's get started.
IF SUM([Sales]) < [Sales Target] THEN 'Below Target' ELSE 'Above Target' END
In the preceding recipe, Orange indicates Sales below target and blue indicates Sales above target. We also saw two examples of Parameters. Since Parameters are not called from the data source, but instead are created on the fly in Tableau, they don't have any relationship with the data source fields and hence will not affect any field or any view on their own. In order to make them useful, we need to call them in our view. It is of no use to create a Parameter and not call it in our view. In the preceding recipe, we called the Parameter in a Filter or a Set as well as in a Calculated field. We can also call Parameters in Bins to make the bin size flexible as well as in Reference Lines (we will discuss reference lines in future chapters).
There are three types of Parameter controls available in Tableau and these will help us specify how the Parameter can accept values. They are as follows:
The availability of these Parameter control options is determined by the data type that is specified. For example, an integer parameter can accept All values, or a List, or even a Range, whereas a string parameter can only accept All values or a List, but does not support a Range.
We have already seen the All and Range parameter control in the preceding recipe. When we select the List parameter control as an option, then we must specify the list of values. The left column, which is labeled as Value, is where we type the value and the right column, which is labeled as Display As in the display alias. The display alias shows the values that the end user can see in the Parameter. Refer to the following screenshot:
Now, instead of typing the values and the display alias, we can also copy and paste a list of values by selecting the option of Paste from Clipboard, or we can also add the members of a field as the list of values by selecting the Add from Field option. However, we need to remember that even though we have the option of Add from Field, the Parameter will still be static in nature. This means that the Parameter will not dynamically update itself if a new entry is made in the field that we have used to create the Parameter. As of now, the Parameters are static in nature, and will not update automatically even if the backend data source updates.
As of now, the Parameters are available as a single select option, meaning we cannot select multiple values at a time. We can only have one value at a time. For example, if we want to have a Parameter from which we can enter or select a minimum threshold value and a maximum threshold value, then we will have to create two Parameters, one which will help us enter the minimum value and the other which helps us enter the maximum value.
Parameters can be used in many ways to give us immense flexibility. One interesting way to use Parameters is to swap the dimensions or measures on the fly or change the view on the fly. Refer to the following links to know more:
3.148.144.228