KNOWLEDGE BASE

Creating a Date Filter that Defaults to a Relative Date


Published: 15 May 2013
Last Modified Date: 20 Aug 2018

Question

How to create a date filter that always defaults to a relative date (such as yesterday or today).

Environment

Tableau Desktop

Answer

CLICK TO EXPAND STEPS
Example 1: Default to Yesterday

Option 1

  1. Right-click and drag the date dimension to the filter shelf.
  2. Select Relative dates > Yesterday.
  3. From the filter shelf, right-click the date dimension and select Show Filter.

Option 2

  1. Create a calculated field by selecting Analysis > Create Calculated Field to create a calculated field.
  2. In the Calculated Field dialog box that opens, enter a name for the field.
  3. In the formula field, create a calculated field similar to the following:
    	[Date Field]=today()-1
    
    • where [Date Field] is the date field being used in the view. Click OK.
  4. Drag the newly created calculated field from the Dimensions pane to the Filter shelf.
  5. In the Filter dialog box that opens, select True, and then click OK.
  6. From the filter shelf, right-click this new calculated field and select Show Filter
To view the steps showed in the below video, please expand the above section.
Note: the video has no sound.
 
CLICK TO EXPAND STEPS
Example 2: Today

Option 1: Always Today

This option will always show today only. There are two ways to implement Option 1:

Create a calculation to be used in place of the original date field. For example:
IF [Order Date] = TODAY() THEN [Order Date] END
OR
Create a T/F boolean calculation and place the field on the filter shelf, set to True:
[Order Date] = TODAY()

To view the steps showed in the below video, please expand the above section.
Note: the video has no sound.

    Option 2: Default Today, Select Other Date

    This option defaults the view to today, but allows users to select a specific date from a parameter control.
    1. In Tableau Desktop, connect to the Sample - Superstore sample data source.
    2. Open the Data pane menu using the drop-down arrow in the upper-right corner and then select Create Parameter.
    3. In the Create Parameter dialog box, do the following, and then click OK:
      • Name the parameter. In this example, the parameter is named [Select Date].
      • For Data Type, select Date & time.
      • For Allowable values, select List.
      • Click Add from Field > Order Date.
      • For Data Type, change the data type from Date & time to String.
      • For List of values, add Today to the list. Drag Today to the top of the list.
      • For Current value, enter Today.
    4. In the Data pane, click the drop-down arrow next to the parameter and then select Show Parameter Control.
    5. Select Analysis > Create Calculated Field.
    6. In the Calculated Field dialog box that opens, do the following and then click OK:
      • Name the calculated field. In this example, the calculated field is named [Select Date Conversion].
      • In the formula field, create a calculated field like the following: 
        IF [Select Date]="Today" THEN TODAY()
        ELSE DATE([Select Date])
        END
    7. Select Analysis > Create Calculated Field.
    8. In the Calculated Field dialog box that opens, do the following and then click OK:
      • Name the calculated field. In this example, the calculated field is named [Select Date Calculation].
      • In the formula field, create a calculated field like the following: 
        IF [Select Date Conversion]=[Order Date] THEN [Order Date]
        ELSE DATE(Today())
        END
    9. Add the new [Select Date Calculation] field to the view and use it as you would use a normal date field.
    To view the steps showed in the below video, please expand the above section.
    Note: the video has no sound.
    Did this article resolve the issue?