KNOWLEDGE BASE

How To Group Different Measures Under A Common Header


Published: 28 Apr 2020
Last Modified Date: 05 Apr 2023

Question

How to create headings that group measures in a view where every bar/line/column is a different measure field.

Environment

  • Tableau Desktop

Answer

The attached example workbook uses the sample data set Superstore to demonstrate directions for the following options.

Option 1: Pivot the measures

First pivot the desired measure fields into a field containing the measure names and another one containing the measure values to replace the Tableau-generated [Measure Names] and [Measure Values]. Then write a calculation that groups measures.
  1. For some data sources, if none of the desired measures are calculated fields, then you may be able to pivot the measure fields in Tableau Desktop. For all other cases, pivot the measure fields in Tableau Prep or in the database. In this example, the following steps were taken:
    1. Navigate to the Data Source tab
    2. Ctrl + click to select Sales, Quantity, Discount, and Profit so that all 4 measures are highlighted
    3. Right-click any highlighted measure and select Pivot
  2. Select Analysis > Create Calculated Field.
  3. In the Calculated Field dialog box that opens, do the following, and then click OK:
    1. Name the calculated field. In this example, the calculated field is named "Measure Groups"
    2. In the formula field, create a calculation similar to the following:
       
      IF [Pivot Field Names] IN ('Sales','Profit')
      THEN "Header One"
      ELSE "Header Two"
      END
  4. Drag Measure Groups and Pivot Field Names to the Columns shelf
  5. Drag Pivot Field Values to the Rows shelf
  6. Optional formatting:
    1. Navigate to Analysis > Table Layout then uncheck Show Field Labels for Columns
    2. Right-click Pivot Field Names on the Columns shelf and select Sort...
    3. In the Sort dialog, rearrange the Measure Names as desired
Option 2: Combine views on dashboard

Create multiple views, each one only containing measures that belong to one group. Use calculations with a single text value to create different headers on each sheet. And finally combine all views on a dashboard.

  1. Duplicate the original worksheet and rename the worksheet to reflect one measure group heading. For example "Heading One"
  2. On the duplicate worksheet, remove measures that do not belong to the measure group heading "Heading One"
  3. Select Analysis > Create Calculated Field.
  4. In the Calculated Field dialog box that opens, do the following, and then click OK:
    1. Name the calculated field. In this example, the calculated field is named "Heading One"
    2. In the formula field, create a calculation similar to the following: "Heading One" 
  5. Drag Heading One onto the Columns shelf before Measure Names
  6. Navigate to Analysis > Table Layout and uncheck Show Field Labels for Columns
  7. Repeat steps 1-7 for every measure group heading
  8. For all views except for the first measure group heading, right-click the Value axis and uncheck Show header
  9. Create a new dashboard and add all views to the dashboard
  10. Optional formatting: adjust Outer Padding so that there is no space between views

 
Did this article resolve the issue?