KNOWLEDGE BASE

Changing the Date Level Dynamically


Product(s): Tableau Desktop
Version(s): All
Last Modified Date: 16 Aug 2016

Article Note: This article is no longer actively maintained by Tableau. We continue to make it available because the information is still valuable, but some steps may vary due to product changes.


 

Create a workbook that allows you to dynamically change the view based on a specified date level. For example, suppose you want to create a workbook that allows you to see interchangeably display sales data by year, month, or day. Use this example and the procedure below to create a line chart that will allow you to dynamically display sales data based on date levels that you can switch between.

Step 1: Create custom date fields

Create custom date fields so that you can isolate specific date levels in the existing date field.

  1. In Tableau Desktop, connect to the data source. For this example, connect to the Superstore data source.
  2. In the Data Window, right-click the Order Date field, and then select Create Custom Date.
  3. In the Create Custom Date dialog box, do the following:
    1. Give the custom date a name. For this example, enter Order Date - Year.
    2. For Detail, select Years. Leave the Date Value selected.
    3. Click OK.
  4. Repeat steps 2 -3 to create custom dates for both month and day.

Step 2: Create a parameter to use as the date level selector

  1. Right-click the Data window, and then select Create Parameter.
  2. In the Create Parameter dialog box, do the following:
    1. Give the parameter a name. For this example, use Date Level Selector.
    2. For Data Type, select String.
    3. For Allowable values, select List.
    4. For List of values, enter the following and then click OK:
      • Year
      • Month
      • Day
  3. In the Data window, right-click the parameter, and then select Show Parameter Control.

Step 3: Create a calculated field

Create a calculated field that displays the data based on the date level specified by the date level selector parameter.

  1. Select Analysis > Create Calculated Field.
  2. In the Calculated Field dialog box, do the following:
    1. Give the calculation a name. For this example, use Date Selector.
    2. In the formula field, create a calculated field similar to the following:
    CASE [Date Level Selector]
    WHEN 'Year' THEN [Order Date - Year]
    WHEN 'Month' THEN [Order Date - Month]
    WHEN 'Day' THEN [Order Date - Day]
    END
  3. Click OK.

Step 4: Create the final view

  1. In the Data window, right-click the Date Selector field, and then select Convert to Discrete.
  2. Drag the Date Selector field to the Columns shelf.
  3. On the Columns shelf, right-click the Date Selector field, and then select Exact Date and Discrete.
  4. Drag the Sales field to the Rows shelf.

 

Alternate Search Terms:date switcher, dynamic dates, date picker
Did this article resolve the issue?