Last modified date: 20 Jul 2023
Environment
Tableau DesktopAnswer
The above steps can be reviewed in the attached workbook dynamically change date level.twbx.CLICK TO EXPAND STEPS
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 dialogue box, do the following:
- For Detail, select Years. Leave the Date Value selected.
- If desired, give the custom date a name. In this example,keep default as Order Date - Year.
- Click OK.
- Repeat steps 2 -3 to create custom dates for both month and day.
CLICK TO EXPAND STEPS
Step 2: Create a parameter to use as the date level selector
- Select Dimension drop-down, and then select Create Parameter.
- In the Create Parameter dialogue 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 Year, Month, and Day, then click OK.
- In the Data window, right-click Date Level Selector and choose Show Parameter Control.
CLICK TO EXPAND STEPS
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.
- Name the field Date Selector, enter the following calculation, then click OK:
CASE [Date Level Selector]
WHEN 'Year' THEN [Order Date - Years]
WHEN 'Month' THEN [Order Date - Months]
WHEN 'Day' THEN [Order Date - Days]
END
CLICK TO EXPAND STEPS
Step 4: Create the view
- Drag Date Selector to Columns.
- On the Columns shelf, right-click the Date Selector field, and then select Exact Date and Discrete.
- Drag Sales to Rows.
Additional information
To view the steps showed in the below video, please expand the above section.Note: the video has no sound.
Thank you for providing your feedback on the effectiveness of the article.
Open new case
Continue searching
Knowledge Base
Community
Product help
Training and tutorials