Friday, August 21, 2020

Creating Date Range Filter with Dynamic End Date = Max Date

Since the version 2020.1, Tableau has a new dynamic parameter feature that solves a long standing problem: Making a date range filter with end date default to the max date in the data source.

Here is how it works:

1.Create a field Max Date = {Max(Order Date)}

2.Create a parameter End Date as follows. Set value when workbook opens to be the above Max Date.


3.Create your regular Start Date parameter and a date range filter

Here we got an example workbook for you to download. It will always open to the last date of the data set as the End Date.

Update: I found an issue when working with data extract on server. The solution is 

  1. Create a local copy of the extract.
  2. Create Max Date and publish data extract to the server along with the field.
Then the dynamic parameter works.


5 comments:

  1. Good post! I have one question: I have a workbook. The data is refreshed every year at Jan 5. With the dynamic parameter and the method you introduce in this post, I can always show the Jan 5 of latest year as the default parameter value. That's good. However, if I want the parameter only show the Year, no month and date, how can I set the parameter? For example, if the latest date is Jan 5 2019, I want the default parameter shows 2018, which means it is 2018 data. If the latest date is Jan 5 2020, I want the default parameter shows 2019. Formerly with static parameter, I can input different data for value and display. For example, I can set the value as Jan 5, 2020, and the display as 2019. But with dynamic parameter, I cannot do in such a way. Thanks for help!

    ReplyDelete
    Replies
    1. Specific to your case, create a field like this instead MaxDate: MaxYear = Year( {Max(Order Date)}) -1
      Or MaxYear=Year(DateAdd('day',-5, {Max(Order Date)})) Give it a try and let me know if this works.

      Delete
    2. And "End Date" should be "End Year". Date Type is either Date or Integer.

      Delete
  2. Is there a way to have a [Start Date] and [End Date] parameter filters as a field where the user can manually enter data or select from a calendar (so it would be the range option instead of list), AND have the [End Date] default to the latest date? I know we would need to use the "Range" section when we edit the parameters, but curious if there is a way to have the end date as the latest date by default but the user would be able to select other dates if they wanted to

    ReplyDelete
    Replies
    1. Yes you can. Any of the 3 options will work: All, List, and Range.

      Delete