Last Modified Date: 24 May 2023
Environment
Tableau DesktopResolution
Depending on the filter type and the use case, the best solution may vary. All options below are demonstrated in the packaged workbook downloadable from the right-hand Attachments section of this article.
Option 1: Use dynamic parameters
Starting in Tableau Desktop 2020.1 dynamic parameters allow a calculation to be used as the default value of a parameter. See Create Parameters
Option 2: Use a relative date filter
Relative date filters will automatically update the dates to the relative range selected, such as yesterday. The user can then change the relative range. For more information, see Create Relative Date Filters
Option 3: Use a discrete date filter
Use Lastest Date Preset feature. The Latest Date Preset feature will update to the most recent date every time the workbook is opened.
Note: this feature is only available for discrete date list filters, and not range of date filters or filters that allow the user to pick a date from a calendar.
Option 4: Use a Type-In Parameter
Create a parameter where the user can type in a default keyword, such as "yesterday", or any date to filter the view. The "yesterday" value can be set to dynamically return yesterday's date in a calculated field. Please note, this method does not provide the drop-down list of dates or slider, and only one date can be typed into in the parameter.
- Open the Data pane menu using the drop-down arrow in the upper-right corner and select Create Parameter.
- In the Create Parameter dialog box, do the following:
- Name the parameter. In this example, the parameter is named "Enter 'Yesterday' or a Date".
- For Data Type, select String.
- For Current value, enter "Yesterday".
- For Allowable values, select All.
- Click OK.
- Right-click [Enter 'Yesterday' or a Date] in the Data pane, and select Show Parameter Control.
- Select Analysis > Create Calculated Field
- In the Calculated Field dialog box that opens, do the following:
- Name the calculated field. In this example, the calculated field is named "Date Conversion"
- In the formula field, create a calculated field like the following:
IF [Enter 'Yesterday' or a Date] = "Yesterday" THEN TODAY() - 1 ELSE DATE( [Enter 'Yesterday' or a Date] ) END
- Click OK
- Create a calculated field with a name like for example "opt 3: date filter" with a calculation similar to the following:
[Date Conversion] = [Order Date]
- Drag [opt 4: date filter] to the Filter shelf.
- In the Filter dialog, check True and click OK.
- The user can now type in a date or a defined phrase into the parameter control.
Option 5: Use Start and End Parameters to define a range
Step 1: Create Start and End Date Parameters
- Right-click in the Data window and then select Create Parameter.
- In the Create Parameter dialog box, do the following, and then click OK:
- Name the parameter. In the example workbook, the parameter is named "Start date".
- For Data Type, select Date.
- For Allowable values, select All.
- Right-click the parameter and then select Show Parameter Control.
- Repeat steps 1-3 to create an "End date" parameter.
Step 2 (Optional): Create a Parameter to Control a Filter
- Right-click in the Data window and then select Create Parameter.
- In the Create Parameter dialog box, do the following, and then click OK:
- Name the parameter.In the example workbook, the parameter is named "Choose Filter Range".
- For Data Type, select String.
- For Allowable values, select List.
- In List of values, add any desired ranges. This example includes: "All values", "Start to End Dates", "Last 7 days", "Start Date to Today", and "1 Month before End Date"
- Right-click the parameter and then select Show Parameter Control.
Step 3: Create a Calculated Field to Use as a Filter
- If not using the optional parameter from Step 2, select Analysis > Create Calculated Field.
- In the Calculated Field dialog box that opens, do the following:
[Order Date] >= [Start Date] AND [Order Date] <= [End Date]
- Name the calculated field. In the example workbook, the calculated field is named "opt 4: simple date filter".
- In the formula field, create a calculated field similar to the following:
- Note: Replace [Order Date] with the date field you would like to filter.
- Click OK
- If using the optional parameter from step 2, create a calculated field with a name like "opt 4: date filter" with a calculation similar to the following:
[Choose Filter Range] = "All values" OR ( [Choose Filter Range] = "Start to End Date" AND [Order Date] >= [Start Date] AND [Order Date] <= [End Date] ) OR ( [Choose Filter Range] = "Last 7 days" AND [Order Date] > DATEADD('day',-7,TODAY()) AND [Order Date] <= TODAY() ) OR ( [Choose Filter Range] = "Start Date to Today" AND [Order Date] >= [Start Date] AND [Order Date] <= TODAY() ) OR ( [Choose Filter Range] = "1 Month before End Date" AND [Order Date] >= DATEADD('month', -1, [End Date]) AND [Order Date] <= [End Date] )
- Drag either [opt 4: simple date filter] or [opt 4: date filter] to the Filter shelf.
- In the Filter dialog box that opens, check True.
- Click OK.
Cause
The static default is the value set in the filter, when the workbook is saved or published, or when the user creates a custom view of a published view. The filter will revert to the static default when the workbook is opened, the published view or custom view is loaded, or the revert button is clicked on the published view.The ability to set a dynamic default selection in a filter is not currently built into the product.
Additional Information
To voice your support for the inclusion of this enhancement in a future product release, add your vote to the following Community Ideas:
Starting in Tableau Desktop 2018.2, third party extensions can be added to Tableau Dashboards to add increased functionality. Therefore you may be able to find an extension that provides the desired filter behavior. For more information, see Use Dashboard Extensions and Extensions for Tableau Dashboards to get started.