KNOWLEDGE BASE

Creating Dynamic Column Headers


Published: 24 Apr 2017
Last Modified Date: 28 Sep 2017

Question

How to create dynamic column headers in a dashboard using parameters and calculated fields.

Environment

Tableau Desktop

Answer

The below steps are specific to the SuperStore Sample data source and can be reviewed in the attached workbook Creating Dynamic Column Headers.twbx.  

CLICK TO EXPAND STEPS
Step 1: Create 4 Parameters

Parameter: Range 1 - Start

  1. Right-click in the Data window and then select Create Parameter.
  2. In the Create Parameter dialog box, do the following, and then click OK:
    • Name the parameter. In the example workbook, the parameter is named Range 1 - Start.
    • For Data Type, select Date & Time.
    • For Display Format, select the desired format.
    • (Optional) you can limit the range that will appear in the parameter controls by selecting Range for Allowable Values, and then setting maximum and minimum values.

Parameter: Range 1 - Stop

  1. Right-click in the Data window and then select Create Parameter.
  2. In the Create Parameter dialog box, do the following, and then click OK:
    • Name the parameter. In the example workbook, the parameter is named Range 1 - Stop.
    • For Data Type, select Date & Time.
    • For Display Format, select the desired format.
    • (Optional) you can limit the range that will appear in the parameter controls by selecting Range for Allowable Values, and then setting maximum and minimum values.

Parameter: Range 2 - Start

  1. Right-click in the Data window and then select Create Parameter.
  2. In the Create Parameter dialog box, do the following, and then click OK:
    • Name the parameter. In the example workbook, the parameter is named Range 2 - Start.
    • For Data Type, select Date & Time.
    • For Display Format, select the desired format.
    • (Optional) you can limit the range that will appear in the parameter controls by selecting Range for Allowable Values, and then setting maximum and minimum values.

Parameter: Range 3 - Stop

  1. Right-click in the Data window and then select Create Parameter.
  2. In the Create Parameter dialog box, do the following, and then click OK:
    • Name the parameter. In the example workbook, the parameter is named Range 2 - Stop.
    • For Data Type, select Date & Time.
    • For Display Format, select the desired format.
    • (Optional) you can limit the range that will appear in the parameter controls by selecting Range for Allowable Values, and then setting maximum and minimum values.
CLICK TO EXPAND STEPS
Step 2: Create 4 Calculated Fields

Calculated Field: Range 1 Sales

  1. Select Analysis > Create Calculated Field
  2. In the Calculated Field dialog box that opens, name the calculated field Range 1 Sales
  3. Enter the following formula and then click OK:
  4. IF [Order Date]>= [Range 1 - Start] AND [Order Date]<=[Range 1 - Stop] THEN ([Sales]) ELSE 0 END 

Calculated Field: Range 2 Sales

  1. Select Analysis > Create Calculated Field
  2. In the Calculated Field dialog box that opens, name the calculated field Range 2 Sales
  3. Enter the following formula and then click OK:
  4. IF [Order Date]>= [Range 2 - Start] AND [Order Date]<=[Range 2 - Stop] THEN ([Sales]) ELSE 0 END 

Calculated Field: Dynamic Range 1

  1. Select Analysis > Create Calculated Field
  2. In the Calculated Field dialog box that opens, name the calculated field Dynamic Range 1
  3. Enter the following formula and then click OK:
  4. STR((DATENAME('month', [Range 1 - Start]))+ " " 
    + DATENAME('day', [Range 1 - Start]) + ", " 
    + DATENAME('year', [Range 1 - Start])) + " - " 
    + str((DATENAME('month', [Range 1 - Stop]))+ " " 
    + DATENAME('day', [Range 1 - Stop]) + ", " 
    + DATENAME('year', [Range 1 - Stop])) 

Calculated Field: Dynamic Range 2

  1. Select Analysis > Create Calculated Field
  2. In the Calculated Field dialog box that opens, name the calculated field Dynamic Range 2
  3. Enter the following formula and then click OK:
  4. STR((DATENAME('month', [Range 2 - Start]))+ " " 
    + DATENAME('day', [Range 2 - Start]) + ", " 
    + DATENAME('year', [Range 2 - Start])) + " - " 
    + str((DATENAME('month', [Range 2 - Stop]))+ " " 
    + DATENAME('day', [Range 2 - Stop]) + ", " 
    + DATENAME('year', [Range 2 - Stop])) 
CLICK TO EXPAND SOLUTION
Step 3: Create the visualization

Create the Views

  1. In Sheet 1
    1. From Dimensions, drag Order Date to the Columns shelf.
    2. From Dimensions, drag Customer and Product Name to the Rows shelf.
    3. In the view, right-click the Order Date header, and select Hide Field Labels for Columns. 
    4. Right-click the four parameters and then select Show Parameter Control for all of them.
  2. Sheet 2
    1. From Dimensions, drag Dynamic Range 1 to the Text shelf.
    2. Adjust how the sheet will fit as desired.
  3. Sheet 2
    1. From Dimensions, drag Dynamic Range 2 to the Text shelf.
    2. Adjust how the sheet will fit as desired.

Create the Dashboard

  1. From Dashboard, drag Sheet 1 onto the dashboard.
  2. In the Dashboard pane, click Floating under the Objects section.
  3. Drag Sheet 2 onto the dashboard.
  4. In the view, right-click the Sheet 2 title, and then select Hide Title.
  5. Place Sheet 2 above the appropriate column, and then resize the dashboard object as needed.
  6. Repeat Steps 3-5 with Sheet 3.
Select a start and stop date from the quick filters on the right to update the headers.
 
To view the steps showed in the below video, please expand all the above sections.
Note: the video has no sound. To view the video in high quality, click the YouTube icon below to watch it on YouTube directly.
Did this article resolve the issue?