KNOWLEDGE BASE

Dynamically Grouping and Ungrouping Dimensions


Published: 28 Aug 2013
Last Modified Date: 20 Jul 2023

Question

How to dynamically group and ungroup dimensions. 

For example, your data contains a the Maine state as both "Maine" and "MA" in the underlying data. This article will explain how to group both dimensions into one. 

Environment

  • Tableau Desktop

Answer

Option 1

The below example can be reviewed in the attached workbook State Group Exampe.twbx. 
  1. Create a Parameter > set the Data type to String > set the List of values > Include "Group" and "UnGroup". 
  2. Create a Calculated field to group the desired Dimensions. In this example, the calculated field is called "Group or Ungroup" and contains the below formula: 
If [State]="MA" or [State]="Maine" then 
  If [Group or Ungroup]="Group" then "Maine Group"
    Else [State]
  End
Elseif [State]="MO" or [State]="Montana" then 
  If [Group or Ungroup]="Group" then "Montana Group"
    Else [State]
  End 
 Else [State]
End
  1. Drage this new Calculated field to replace the original Dimension.
The calculated field example groups "MA" and "Maine" into a single value of "Maine Group" and creates the value "Montana Group" in a similar manner. Changing the Parameter to "Ungroup" returns the view to the original Dimension values. 

Option 2

To create a subset of members within a field that automatically updates when new data is added, it might be best to create a set. More information about sets is available from our online Product Help: Sets
Did this article resolve the issue?