Chapter 68. 3 More Innovative Ways to Use Dates: Tip 3
How to Automatically Change Date Granularity Based on Days in Range
Iâve shared before how to let your end users change the date part of a line graph in Tableau (see Chapter 66 from Practical Tableau, OâReilly 2018). Then this tactic was made even better with Tableau Parameter Actions, which allow the user to change the date part using a button (Chapter 70). These are both useful techniques for quickly making line graphs more and less granular in Tableau.
Well, letâs make this tactic better once again by automatically changing the date granularity to the most appropriate date part based on the number of days in the selected date range. This chapter shows you how to change the date part of a line graph from day, to week, to month based on whether there are 30 or fewer, 90 or fewer, or more than 90 days on the view, respectively.
This approach requires five short steps:
-
A start date parameter
-
An end date parameter
-
A calculated field to compute the number of days in the selected range
-
A date filter that keeps only the selected dates on the view
-
A calculated field to appropriately truncate the date being used in a line graph
If you are already using parameters to normalize your date ranges on the same axis as is described in Chapter 53, you will have already completed the first three steps.
First, set up your start date and end date parameters. These are simply parameters created with a data type of Date; ...
Get Innovative Tableau now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.