KNOWLEDGE BASE

Set Default Axis Range Using Calculations and Parameters


Published: 27 Mar 2024
Last Modified Date: 28 Mar 2024

Question

How to set the default axis range using calculations and parameters. The example below shows you how to - 
- Set the start date selected on the parameter, 
- and set the end date as "N days later" from the date selected on the paramer.
- and using the above setting as the default when you open the workbook or refresh the date source.

 

Environment

  • Tableau Desktop 2023.3 or later
  • Windows 10

Answer

1. Create a parameter [DATE_START] used for selecting start date of axis range.
Date type: Date
Allowable values: Range
Range of values: 
Minimum 3/27/2019
Maximum 1/5/2023
User-added image

2. Create a parameter [$$DATE_RANGE] used for selecting start date of axis range to control the range of N days later.
User-added image

3. Create a calculation field [DATE_END_calc] to get the date of [$$DATE_RANGE] days later.
DATE({ FIXED :MAX(DATEADD('day',[$$DATE_RANGE],[DATE_START]))})


4. Create a date type parameter [DATE_END] as below
User-added image
and set the [DATE_END_calc] as the default value of parameter [DATE_END] by clicking on [When workbook opens]>[DATE_END_calc], then click on [OK] button to save the changes.
User-added image

5. Right click on the date axis and click on [Edit axis] from the context menu. then set the range as [Custom] in the window below, and select [DATE_START] for the start date and [DATE_END] for the end date.
User-added image

6. After changing the value of [DATE_START] parameter. or the value of [$$DATE_RANGE], reopen the workbook or refresh the data source could enable the changes to be reflected.

Please check the sample workbook attached.

 
Did this article resolve the issue?