In the previous article, we introduced ourselves on how to create a parameter. Therefore, in today’s article we would like to move a notch higher and explore how we can apply this parameter with bins. Our goal is to empower the end user of our report with levers to choose the bin size of an histogram graph, rather than using the fixed bins.
Recap on Histogram
So, what is a histogram? Wikipedia defines histogram as an accurate representation of the distribution of numeric data. Therefore, guided by the previous article on how to create an histogram graph, we’ll use Superstores data to show distribution of product quantities. Our goal is quantifying the number of products ordered in certain quantities (bins), in other words the number of products ordered in quantities of 2, 3, 4 and so forth. On top of this, we would like to enable the end user with levers to decide the bin size they would like to use.
But first, lets do a recap by creating a simple histogram graph.
Once connected to Superstores data set, you can create a histogram as follows;
Right click on Quantity > Create > Bins…
Use the standard bin generated as show below to create the dimension 'Quantity (bin)'.
Let’s build our histogram as follows;
Drag the new field we’ve created ‘Quantity (bin)’ to the columns shelf.
Drag CNT(Quantity) or SUM(Number of Records) to the rows shelf. (Note, this will count every product in our database).
Note; This histogram is built on a fixed bin size and therefore we'll need to parameterize it to meet our objective.
Adding parameter to our bin
To do so, right click on the dimension ‘Quantity (bin)’ > Edit… Under Size of bins we’ll select our parameter if we’ve already created it, but for this case we’ll Choose ‘Create a New Parameter…’ since our parameter is not ready.
On the pop-up menu;
Rename the parameter as ‘No. of Quantities’
Set the current value as 1.
Under Allowable values select 'Range' and set the minimum value as 1 and maximum value as 4.
Use step size of 1.
Note: This implies that the end user can use any value from 1 to 4 as the size of bin.
Executing this does the following;
The bin size automatically changes to what we had set as our current value in the parameter i.e 1 for this case.
Our parameter ‘No. of Quantities’ is automatically displayed at the top right corner of our window. If this is different for your case, check at the bottom of the data pane screen, right click on the parameter we’ve created > ’Show Parameter Control’.
Optional; Note, you can change the parameter type from a ‘Type in’ parameter to a ‘slider’.
With this parameterized histogram, using parameters, users now have the flexibility of deciding on the size of bin they would like to use, with metrics updating automatically as the bin size is updated. Like in the case of filters, parameters too can be formatted and customized as per the user needs.
In the next article on application of parameters, we’ll look at how we can use parameters with calculated fields. Stay tuned.
To receive more of the Tableau tips and tricks, kindly join our mailing list by subscribing below.
Thank you for reading.