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.
- In Tableau Desktop, connect to the data source. For this example, connect to the Superstore data source.
- In the Data Window, right-click the Order Date field, and then select Create Custom Date.
- In the Create Custom Date dialog box, do the following:
- Give the custom date a name. For this example, enter Order Date - Year.
- For Detail, select Years. Leave the Date Value selected.
- Click OK.
- 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
- Right-click the Data window, and then select Create Parameter.
- In the Create Parameter dialog box, do the following:
- Give the parameter a name. For this example, use Date Level Selector.
- For Data Type, select String.
- For Allowable values, select List.
- For List of values, enter the following and then click OK:
- 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.
- Select Analysis > Create Calculated Field.
- In the Calculated Field dialog box, do the following:
- Give the calculation a name. For this example, use Date Selector.
- 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]
- Click OK.
Step 4: Create the final view
- In the Data window, right-click the Date Selector field, and then select Convert to Discrete.
- Drag the Date Selector field to the Columns shelf.
- On the Columns shelf, right-click the Date Selector field, and then select Exact Date and Discrete.
- Drag the Sales field to the Rows shelf.
Alternate Search Terms:date switcher, dynamic dates, date picker