KNOWLEDGE BASE

Creating Groups Using Calculated Fields


Product(s): Tableau Desktop
Version(s): All
Last Modified Date: 16 Aug 2016

Use groups to refine views and identify the exact information you want to draw attention to.

You can create ad-hoc groups by selecting marks in the view and then clicking the group button. You can also create groups with a calculated field. While ad-hoc groups are easy to create, sometimes creating a group from a calculated field is better.

Create a group from a calculated field when you want to:

  • Use groups in a calculation. You cannot reference ad-hoc groups in a calculation.
  • Blend data using groups created in the secondary data source. Only calculated groups can be used in data blending if the group was created in the secondary data source.
  • Use a group in another workbook. You can easily replicate a group in another workbook by copy and pasting a calculation. 

Create a calculated field

To create a groups using a calculated field, you must first know the members of the dimension that will comprise the group.

Note: If there are aliases on the members of the dimension, the calculation must use the original member name.

Step 1 

Right-click (Control-click on a Mac) in an empty area in the Data pane and choose Create Calculated Field.

Step 2 

Create a named calculated field with an expression like the following:

IF [Customer]=’Jumbo Box’ then ‘Big Containers’
ELSEIF [Container]=’Jumbo Drum’ then ‘Big Containers’
ELSEIF [Container]=’Large Box’ then ‘Big Containers’
ELSEIF [Container]=’Medium Box’ then ‘Midsize Containers’
ELSEIF [Container]=’Wrap Bag’ then ‘Midsize Containers’
ELSEIF [Container]=’Small Box’ then ‘Little Containers’
ELSEIF [Container]=’Small Pack’ then ‘Little Containers’
END

Step 3 

Now use this field as a group with three values: Big Containers, Midsize Containers, and Little Containers.  

 

Did this article resolve the issue?