Last week we learnt creating adjustable reference lines and changing chart color based on reference line using parameters in Tableau. Parameters allow you to give you users control over the visualization. For instance, a reference line might help show users sales before and sales after a particular date
Here I am using “super store” data set. I am going to Show the Sales before and Sales after the Reference Date, which the user can change.
First, creating a line chart “sum of sales by day”
Drag the “order date” field to columns shelf and click on the pill and select “day” from the list as shown in the below screenshot.
And drag the “sales” field to rows shelf as below
Now create a parameter
In the Data pane, click the drop-down arrow in the upper right corner and select ‘Create Parameter’
Name: Enter the parameter name, this parameter will appear as new field to the bottom left hand side of the data pane
Data Type: Click on the down arrow and select the data type which is suitable to the field values. Here I selected “date” data type because we are creating the parameter for date field
Current Value: This is the value that your parameter will show by default on your view.
Display Format: Here Tableau will display “automatic” by default. And you can also select the format based on the requirement.
Allowable Values: There are three options here that your parameter will display: all, list and range. The ‘All’ option will allow the user to enter any value of their choice; the ‘List’ option allows you to select a predetermined set of values you want the user to be able to select from and must correlated to a data field in your view but the Display as can be anything. The Range option is available for float, integer, date as well as date and time. In range option we can assign min and max range of values.
In this example I select Range option then select minimum and maximum checkboxes and finally add the values from “order field” as show in the below screenshot
Click “ok” . This parameter will appear as new field to the bottom left hand side of the data pane as shown in the below screenshot
Right click on the parameter on the bottom left of your screen and select ‘Show parameter control’. This will now appear on the top right side of the workbook as a drop down.
Add the Reference Line
Go to the Analytics Pane, to the left of the Data pane, select the reference line and drag it onto the graph. A window will pop up with three options. Select the “Table” option. That means this reference line will display for entire table
After that reference line window will display as shown below
Value: On your value line drop down menu select your parameter (Reference date).
Remaining options can select based on personal choice.
Successfully added dynamic reference line. Now user can adjust reference line with parameter selection
Adjusting the Colour on either side of the Reference Line
Using two colours before and after reference date is very useful. User can easily distinguish sales before or after reference date. To colour the line chart we need to create a calculated field as shown below
Drag the calculated field to colour as shown below. Adjust the colours to your preference and then update the parameter control to see your graph dynamically update.