How To Tableau: Simple Custom Date Picker
In this how to I show you how to create a simple custom date picker to make it easier for users to pick a date range in Tableau.
Last Updated: 29th January 2021 | Tableau Version Referenced: 2020.4 | Contact: alan.m.murray@icloud.com
Tableau’s date filters are pretty good and tend to do a good enough job of allowing users to select date ranges in most cases, however it’s also relatively easy to create a custom date picker for those occasions when you want something a bit fancier, or if you want the data selector to be easily visible.
Here we show you how to do this, you can find the data and workbooks for this here.
Psst! Are you looking to learn Tableau or improve your data skills? Looking to land a new job, get a promotion or win new clients? If so make sure you check out the recently launched Tableau Academy and take your data skills to the next level with brand new premium lessons and tutorials straight to your inbox every two weeks!
Let’s get started!
1. Create the basic date picker view
Our first step is to create a view with the dates to pick from, here’s how we do that.
Open Tableau Desktop and connect to the EU Superstore Sample data (see link above for a copy).
Create a new sheet and re-name it to Date Picker.
Drag Order Date from the data pane to the filters column, select Month/Year and select a single month and year (this is just to narrow down to a single month while we build the date picker).
Right click Order Date and drag to the Columns shelf card, select Weekday (Order Date) from the blue discrete options (Right clicking as you drag allows you to select the date type you want without having to go back in and change it after).
Repeat the same to put Order Date on the Rows shelf but select Week(Order Date) this time.
Now right click and drag Order Date to the Text card, this time select Day(Order Date)
This will now give you the basic calendar view that we need which should look like this:
And here’s a quick run through of those steps:
2. Create fields to hold your dates
Now we need to create a few fields, one for our beginning date, one for our ending date and one to update those when we click the date picker, plus a parameter to input the values:
Right click in the data pane and select Create new parameter…
Name the parameter Dates String, Set the data type to string and Set the current value to nothing the Press Ok.
Create a new calculated field (Hint: Press Alt then a then c to do this quickly) call it Starting Date and enter the following:
DATE(SPLIT([Dates String],"^",1))
Create a new calculated field (Hint: Press Alt then a then c to do this quickly) call it Ending Date and enter the following:
DATE(SPLIT([Dates String],"^",2))
These will get our beginning and ending date respectively by splitting the date string we’ll create next using a unique character.
Create a new calculated field called Date Updater and copy the following:
IF [Dates String] = '' THEN STR([Order Date])
ELSEIF CONTAINS([Dates String],"^") THEN STR([Order Date])
ELSEIF [Order Date] <= DATE([Dates String]) THEN STR([Order Date])
ELSE [Dates String]+"^"+STR([Order Date]) END
This might look a bit complicated but it’s simply an if function which determines where we’re up to and inserts our begin/end date as appropriate as follows:
If our date string is empty we haven’t put anything in yet so put the selected date into our Dates String.
Otherwise, if the date string already contains our unique character (^) it means we already selected a start and end date so we start again with a new start date by putting the selected date in the Dates String.
If neither of these are true we’ve already entered a starting date. If the selected date is before the starting date we can’t use this as an ending date so we assume the user wanted to re-select a new starting date and we out this into the Dates String.
If we have already selected a starting date and the next selected is after the that we add it as the ending date in our Dates String by appending a unique character and the selected date to the existing Date String.
So we essentially now have a string which will contain ‘Starting Date’ ^ ‘Ending Date’, which we can then use along with a parameter to allow users to click on dates and select a starting and end date.
Here are those step by step steps:
3. Allow users to select dates from the user interface
The next steps is how we put the two pieces above together to allow a user to click on a start and then an end date and have their date filter to the selected dates.
On the Date Picker sheet drag Date Updater to the Details card.
Create a new sheet called Output, for now this is just going to show us the date(s) we’ve selected.
Right click and drag Starting Date onto the Text card and select Date (Discrete).
Do the same with Ending Date.
Optionally click the Text card and the 3 dots to edit the text, enter the following and press OK(this is just to show us what we’ve picked, you don’t have to do this).
You've chosen...
Starting date: <Starting Date>
Ending date: <Ending Date>
Create a dashboard and drag your Date Picker and Output sheets side by side, set both to fit the width.
Go to Dashboard > Actions (Or Ctrl+shift+d)
Click Add Action > Change parameter
Call it Select Date and uncheck the Output sheet.
Under Parameter select Dates String,
Under field select Date Updater and press OK.
Now if you click a date in your Date Picker the first one you select should show as your start date and the next one as your end date. When you pick another date it should reset and select your new starting date (if you pick an end date before the start date it should reset too):
You should also see this updating on the Output sheet you created:
And here’s the step by step view:
4. Apply the date picker to some data
That’s the basics of how the calendar picker would work, we’ll now apply it to some date now so you can see it in action and then we’ll apply some formatting to make it look good.
Create a new sheet called Number of Orders per day.
Create a calculated field and call it Date Filter, paste in the following:
[Order Date] >= [Starting Date] AND [Order Date] <= [Ending Date]
Note: This is a shorter way of writing
IF Order Date >= Starting Date AND Order Date <= Ending Date THEN TRUE ELSE FALSE END.
As long as the order date matches the criteria the result will be true, otherwise it will be false.
Drag your Date Filter field to filter and filter on true only.
Drag Order Date onto the Columns shelf and select Days.
Drag Quantity onto the Rows shelf.
Go back to your dashboard and drag your new sheet onto it.
First click a date in your calendar to be your start date, then click another date to be your end date.
Notice how your chart updates to just show those:
And here’s all of those steps:
5. Make it look good!
We can see this works but it doesn’t look very good, we’ll apply some formatting now to make it look slick!
Remove banding, lines and headers.
Right click any of the weeks on the left hand side and untick Show Header to hide the weeks.
Click Format > Shading (or use the shortcut Alt, o, s). Click rows and slide Band Size all the way to the left to remove the shading.
Select Borders at the top then change Row Divider the None.
Change the font and sizing and remove tooltips
If you’re not a fan of the default fonts click Font at the top and format the font according to what you like.
Close the format menu.
Click the Text card and select the alignment to be Middle Centre
Click the Tooltip card and uncheck Show tooltips to turn them off
Add colour to the dates
To make it easier to see what’s been selected add colours to your dates by changing the Marks type to Circle and adjusting the size accordingly. Click the colour card and change the colour to white and remove the border.
Create a new calculated field called Date Colour and paste this in and press OK:
IF [Order Date] = [Starting Date] OR [Order Date] = [Ending Date] THEN 'Start or End'
ELSEIF [Order Date] > [Starting Date] AND [Order Date] < [Ending Date] THEN 'Middle'
ELSE 'Neither'
END
Drag Date Colour to the Colour, then click Colour > Edit Colour. Select a colour you’d like to use to highlight the selected start and end date for the Start or End value (hint double click the item to select any colour from the colour wheel or picker) and do the same to highlight any dates that fall within this range. Set Neither to white if it isn’t already.
Stop highlighting
You may have noticed when you select a date the others are greyed out, let’s add something to stop this.
Drag Date Updated to the Tooltip card.
Go to the Date Picker sheet and create a new calculated field, call it Prevent Highlighting and put any value in (“A” will do).
Drag it to the Detail card.
Click the Highlighting icon and select Prevent Highlighting.
Go back to your Dashboard and click Dashboard > Actions (or use Alt, b, i) and click Add Action > Highlight.
Under Target Highlighting select the Selected Fields option, choose Prevent Highlighting then press OK and OK again.
Call the action Prevent Highlighting, Make sure only Date Picker is selected in both the Source and Target Sheets panel.
Under Target Highlighting select the Selected Fields option, choose Prevent Highlighting then press OK and OK again.
Now when you click a date it shouldn’t grey out other dates.
And this is how our final output looks:
And here are those final steps:
Selecting dates across months
You may have noticed that we’re just looking at a single month, what if you want to select dates across several months? An easy way to do that is to add the month/year filter to the date picker sheet and show this on the dashboard. We’ve used a slider to accomplish this, there are more creative ways to do it but we’ll leave you to figure those out yourself! :)
Missing Dates
You may notice in August the two dates are missing, this is because we don’t have data in our data set for them. If you have data with missing dates you may need to use a date scaffold to fill in the missing dates. See how to do that here.
Summary
In this How To Tableau I’ve shown you how to create a simple custom date picker, this can be used to place a date picker on a Tableau dashboard and allow users to quickly click to select start and end dates.
The chart in the above is pretty simple but this technique can be used to filter date ranges for an entire dashboard or suite of reports. You can also adapt it to allow users to select the start or end date for a date range or to set a minimum start or end date.
Resources
Below you can find links to the example files used as well as other useful resource files.
Hello,
Is it possible to select only one day using the date picker solution ?
Is there a way to apply the date picker to a dashboard with multiple charts and some tables? I tried adding the "date filter" to the filter section in the worksheet for my table. The table doesn't contain dates so it didn't work.
When a user is in the dashboard and selecting dates with the tool, I'd like for it to also filter the info displayed in the table.