Last Modified Date: 06 Apr 2017
The below steps create a calculation to show the three months prior to an adjustable anchor date.
Step 1: Create a Parameter
- In Tableau Desktop, connect to Superstore sample data.
- Right-click in the Data window and then select Create Parameter.
- In the Create Parameter dialog box, do the following, and then click OK:
- Name the parameter. In the example workbook, the parameter is named Date Control.
- For Data type, select Date & time.
- For Allowable values, select List.
- Click Add from Field, and then select Order Date.
- For Display format, select March, 2011.
- Right-click the parameter and then select Show Parameter Control.
Step 2: Create a Calculated Field
- Select Analysis > Create Calculated Field.
- In the Calculated Field dialog box that opens, do the following, and then click OK:
- Name the calculated field. In the example workbook, the calculated field is named Relative Date.
- In the formula field, create a calculated field similar to the following:
IF DATEDIFF('month',[Order Date],[Date Control])=3 OR
DATEDIFF('month',[Order Date],[Date Control])=2 OR
DATEDIFF('month',[Order Date], [Date Control])=1 OR
DATEDIFF('month',[Order Date],[Date Control])=0
THEN "Show" ELSE "Hide" END
- Drag the newly created calculated field from the Dimensions pane to the Filters shelf.
- In the Filter dialog box that opens, select Show, and then click OK.
Step 3: Create the View
- Drag Order Date to Rows.
- Right-click Order Date on Rows, and then select Month May (2011).
- Right-click Order Date on Rows, and then select Discrete.
- Double-click Sales.
- Use the Date Control parameter control to select an anchor date.
Additional InformationFor a more flexible calculation, in Step 2 above, the 3 can be replaced with a second parameter, such as [Parameter 2], which contains a range of integers such as 0-12. You can then adjust [Parameter 2] to control the range of dates displayed.
To see these steps in action, watch the video below.
Note: Video is silent.
Thank you for providing your feedback on the effectiveness of the article.
Open new Case
Training and Tutorials