KNOWLEDGE BASE

Set a Dynamic Default Selection in a Filter


Published: 23 Oct 2013
Last Modified Date: 14 Sep 2018

Issue

Unable to set an over-ridable dynamic default selection in a filter that the user can later change, for example the largest value, the most recent value, today's value, the first value in the list, etc...

Environment

  • Tableau Desktop

Resolution

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.

CLICK TO EXPAND SOLUTION

Option 1: 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

CLICK TO EXPAND SOLUTION

Option 2: Use a discrete date filter

In Tableau Desktop 10.3 and later, 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.

CLICK TO EXPAND SOLUTION

Option 3: 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.

  1. Open the Data pane menu using the drop-down arrow in the upper-right corner and select Create Parameter.
  2. 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.
  3. Right-click [Enter 'Yesterday' or a Date] in the Data pane, and select Show Parameter Control.
  4. Select Analysis > Create Calculated Field
  5. 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
  6. 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]
               
  7. Drag [opt 4: date filter] to the Filter shelf.
  8. In the Filter dialog, check True and click OK.
  9. The user can now type in a date or a defined phrase into the parameter control.
CLICK TO EXPAND SOLUTION

Option 4: Use Start and End Parameters to define a range

Step 1: Create Start and End Date Parameters

  1. Right-click in the Data window and then select Create Parameter.
  2. 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.
  3. Right-click the parameter and then select Show Parameter Control.
  4. Repeat steps 1-3 to create an "End date" parameter.

Step 2 (Optional): Create a Parameter to Control a Filter

  1. Right-click in the Data window and then select Create Parameter.
  2. 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"
  3. Right-click the parameter and then select Show Parameter Control.

Step 3: Create a Calculated Field to Use as a Filter

  1. If not using the optional parameter from Step 2, select Analysis > Create Calculated Field.
  2. 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
  3. 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]
                )
                 
  4. Drag either [opt 4: simple date filter] or [opt 4: date filter] to the Filter shelf.
  5. In the Filter dialog box that opens, check True.
  6. 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.

Did this article resolve the issue?