It’s possible using a combination of parameters, filters and calculated fields to create complex and advanced date filters in Tableau.
Say you want to see some a time period based upon a user selected time period. You can create a calculated field which will return a result based on what the user selected.
For this example you want the user to select a month, but you want to display results showing data from the month before the user selected month as well the selected month – i.e. the user selects Apr and you also need to display Mar as displayed in the visualisation.
This wouldn’t work with a standard filter, the user would need to select the months they were interested in one by one. Using a parameter and a calculated field is the way around this.
First create a parameter for the user to select the date. For this example the user is going to select a month. The parameter has been called DateSelector.
To have this displayed in the format of MMM YY we need to alter the Display Format. Select Custom and type in the format mmm yy.
Every month the user selects is actually the first day of that month, which is important to know as future date manipulations need to be taken from that date.
The next step is to create the calculated field which says what dates we are going to use based on the value selected by the user. Remember the parameter only actually selects the 1st of the selected month but the user actually thinks they’re selecting the entire month. This means as part of our calculated field we need to specify the entire month is being selected. We also need to select the previous month as that’s what is needed as part of this hypothetical report.
This calculated field is our Filter field.
Note: The field named [Day] is the name of the date field in the example dataset I’m using.
Now we have all of our fields you can construct a worksheet. Right click on the parameter DateSelector and ‘Show Parameter Control’
Drag the DateFilter into the Filter section and set the value to True. Then pull in the other data you want to display in your report. In my example I have shown daily visit data comparing the selected month and the previous month and the sheet is below.
You can make the date filters as advanced as you need, it all depends how complicated you make the calculated field.