Tableau Group By

What is Tableau Group By?

Tableau Group By is a feature in Tableau that allows you to combine the related values in a field. Using Tableau, you can create logical groups using the data values in a field and then use them in your visualizations. For example, suppose you have a field called Fruits and Vegetables with values containing fruit names and vegetable names. In that case, you can create two groups, i.e., Fruits and Vegetables, by combining the relevant values. Tableau groups are helpful in performing scenario analysis and eliminating data errors as they help you combine different values into a logical grouping.

Below is a sample Tableau group by. As you can see, Bookcases and Tables are combined into a single field called Bookcases & Tables, which can be further used in data visualization.

Tableau Group By - Intro
Key Takeaways
  • Tableau Group By allows you to combine the related values in a field.
  • Using Tableau, you can create logical groups using the data values in a field and then use them in your visualizations.
  • Tableau groups are useful in performing scenario analysis and also eliminating data errors as they help you to combine different values into a single group.
  • You can create a group by in Tableau by choosing Create – Group.
  • Tableau allows performing different data aggregations using group by.
  • Tableau group by doesn’t affect the underlying data in Tableau.

How to do Group by in Tableau?

Tableau provides a built-in feature to create, edit, and remove groups as per your visualization requirements. There are various ways to do group by in Tableau.

Let’s look at how you can do it yourself, referencing the steps outlined below:

Source the Data

Step 1: Import your data source into Tableau Public using the File Navigator.

Tableau Group By - Step 1

Create Groups

Step 2: In a new worksheet, right-click on a field for which you want to create a group. 

Select Create – Group from the context menu.

Tableau Group By - Step 2

Step 3: On the Create Group screen, select the logically related values and then click the Group button to create a group. 

Tableau Group By - Step 3

Step 4: Give the newly created group a relevant name. Click OK to save the changes.

Tableau Group By - Step 4

Tableau will create the group, which can be viewed in the Data pane.

Tableau Group By - Step 4 - Group

Edit a group

Step 5: Right-click on the existing group and select Edit Group from the context menu.

Tableau Group By - Step 5

Step 6: On the Edit Group screen, select additional related values. Click on Group to create another group. 

Tableau Group By - Step 6

Step 7: Rename the group by providing a meaningful name. Click on OK to save the changes.

Tableau Group By - Step 7

Step 8: Drag the group to the Columns shelf and Profit to the Rows shelf. Drag the same to the Color and Label on the Marks card. Your Tableau visualization is now ready to view. As you can see, based on the grouping of values, Tableau aggregates the data and displays the values in the view.

Tableau Group By - Step 8

Note: Tableau, by default applies grouping for specific data types in the view. However, you can create custom fields to apply Tableau group by date as well.

In the next section, we will look at different sets of examples demonstrating Tableau groups by usage.

Examples

In this section, we will go through different examples that can be referred to using the Tableau group by.

Example #1 – Group by top N records

In this example, we have demonstrated how to use group by Top N records in Tableau using the Genuine saving dataset. The Genuine saving dataset contains the GDP, gross domestic product that represents a nation’s total income, and genuine savings across different countries and years.

To use group by Top N records in Tableau, you may follow the instructions outlined below:

Step 1: Connect to the Genuine saving dataset from the Tableau interface and import it into the Tableau Desktop.

Tableau Group By - Example 1 - Step 1

Step 2: Create a data visualization by dragging Country to the Columns shelf and GDP to the Rows shelf. Drag GDP to the Label on the Marks card. Tableau will create a bar chart in the view as shown below.

Tableau Group By - Example 1 - Step 2

Step 3: Click on the Sort descending order icon in the Tableau bar icons to sort the data per GDP values.

Tableau Group By - Example 1 - Step 3

Step 4: Right-click on the Data pane. Select Create Parameter.

Tableau Group By - Example 1 - Step 4

Step 5: In the Create Parameter window that opens, specify the choice of values as per below.

Here, we have named the parameter Group by N values, specified the Data type as integer, then the Current value as 3, and the Allowable values as All.

Click on OK to save the changes.

Tableau Group By - Example 1 - Step 5

Step 6: Right-click on the parameter and choose Show Parameter. Tableau will show the current value of the parameter in the right corner of the Tableau view.

Tableau Group By - Example 1 - Step 6

Step 7: Click on the down arrow next to the search box and then select Create Calculated Field.

Tableau Group By - Example 1 - Step 7

Step 8: In the Calculation Editor screen that opens, create a Tableau group by calculated field GDP_RANK by specifying the logic as shown below.

GDP_RANK will rank the countries based on their total GDP values.

Tableau Group By - Example 1 - Step 8

Step 9: Create another Tableau group by calculated field, i.e., CountryGroup as per the logic provided below.

Here, we have divided the groups as per the parameter values dynamically based on the user inputs.

Tableau Group By - Example 1 - Step 9

Step 10: Drag the CountryGroup and Country fields to the Columns shelf and GDP to the Rows shelf.

As you can see, Tableau has created four groups with the top 3 records in each group.

Tableau Group By - Example 1 - Step 10

Step 11: Apply color-coding to the Tableau view by dragging the CountryGroup field to the Color on the Marks card.

Tableau Group By - Example 1 - Step 11

Step 12: Change the parameter value from 3 to 4. You will notice that Tableau has now created 3 groups with top 4 values in each group as shown below.

Tableau Group By - Example 1 - Step 12

Example #2 – Group by month

In this example, we will demonstrate using group by month in Tableau Public. For this demo, we have used the Amazon Sales dataset that contains 100 rows of sales data for Amazon, including the region, country, item type, sales channel, order priority, order date, order ID, ship date, units sold, unit price, unit cost, total revenue, total cost, and total profit.

To use group by month in Tableau, follow the instructions outlined below:

Step 1: Import the Amazon Sales dataset into the Tableau interface using File – Open functionality.

Example 3 - Step 1

Step 2: Create a group by right-clicking on the Order Date field and selecting Create – Custom date.

The idea here is that we will create a group by month based on the Order Date to display the profits made each month.

However, before you apply the Tableau group by date, it is required to transform the Order date field into custom month format.

Example 2 - Step 2

Step 3: In the Create Custom Date screen, provide a meaningful name to the field. Under the Detail, click on the drop-down, and choose Months from the available options.

Tableau Group By - Example 2 - Step 3

Step 4: Select the Date part option and then click OK to save the changes.

Example 2 - Step 4

Tableau will create the custom field Order Month in the Data pane.

Example 2 - Step 4 - Order Month

Step 5: Drag the Order Month to the Rows shelf. Similarly, drag Total Profit to the Text on the Marks card. Tableau will create a text table as shown below.

Example 2 - Step 5

Step 6: Right-click on the Order Month and select Create – Group from the context menu.

Example 2 - Step 6

Step 7: In the Create Group screen, select the relevant values to add them to a group H1. Click on Group.

H1 comprises the months representing the 1st half of the year.

Example 2 - Step 7

Step 8: Here, rename the group as H1 Order and click on OK to save the changes.

Example 2 - Step 8

Step 9: Similarly, right-click on the group and select the remaining values. It is to create another group in the Edit Group screen.

Tableau Group By - Example 2 - Step 9

Step 10: Now, rename the group and click on OK to save the changes.

Tableau Group By - Example 2 - Step 10

Step 11: Drag the fields to the Rows shelf and Total Profit to the Text on the Marks card.

Now you will see we have two groups, H1 Order and H2 Order, displaying the total profits grouped by each month in the Tableau view.

Tableau Group By - Example 2 - Step 11

Example #3 – Group by columns

In this example, we will demonstrate how to group by columns in Tableau using the Education Dataset. The Education Dataset contains the student performance activity of 500 students across 10 key educational metric sales, such as age, gender, grade_level, math_score, reading_score, writing_score, attendance rate, extracurriculars, graduation date, etc.

To perform group by columns in Tableau, follow the instructions outlined below:

Step 1: Import the Education Dataset data into Tableau public using the file navigator. You can view the data in the Data Source tab.

Example 3 - Step 1

Step 2: In a new worksheet, click on the down arrow next to the search text field and choose the Create Calculated Field option.

Example 3 - Step 2

Step 3: In the Calculation Editor screen, create a Tableau group by calculated field after specifying the logic.

Here we have created a Tableau group by calculated field Total Score by summing up the Math score, Reading score and Writing score for each student.

Tableau Group By - Example 3 - Step 3

Step 4: Drag and drop the fields from the Data pane to the Tableau view.

Here, we have dragged the Extracurriculars to the Columns shelf and Gender to the Rows shelf. The Total Score field has been dragged to the Text on the Marks card to create a Tableau text table.

Tableau Group By - Example 3 - Step 4

Step 5: Now in the Tableau view, select Art and Music columns. You will notice a Group icon displayed in the view. Click on the Group icon to group the members of Art and Music columns.

Tableau Group By - Example 3 - Step 5

Tableau will group Art and Music columns to create a new column Art & Music with combined values as shown in the Tableau view.

Important Things to Note

  • Tableau group supports both static and dynamic grouping of values in a data visualization. While static groups remain fixed until you edit them manually, dynamic grouping can be flexible and parameter-driven.
  • Tableau allows combining multiple dimensions using the Combine Fields option.
  • Tableau group by allows you to perform what-if analysis by combining multiple values and running those simulations.
  • You can color a view using groups.

Frequently Asked Questions (FAQs)

1. Can I group data by multiple dimensions in Tableau?

Yes, you can group data by multiple dimensions in Tableau. They include:

• Using Tableau group by calculated fields and applying logical operators to define the conditions
• Use the Combined field option, which allows you to combine two or more fields in Tableau. 

2. What are the different aggregation options available with “Group By” in Tableau?

There are various aggregation options available with the group by in Tableau. They include data aggregation functions like Tableau group by SUM, AVG, Tableau group by count, MIN, MAX, or other functions. Using these functions, you can apply aggregations to your data and use them in visualizations.

3. Does “Group By” affect the underlying data in Tableau?

No, group by doesn’t affect the underlying data in Tableau. Group by essentially combines the data values in a field and then displays the aggregated value in the Tableau view. The underlying data values remain the same in Tableau.

4. How does “Group By” differ from “Filter” in Tableau?

In Tableau, Group By allows you to combine the values in a field to perform data aggregation. It doesn’t exclude any values from the view. A filter allows you to narrow down the dataset by applying specific criteria for your data visualization.

Download Template

This article must help understand Tableau Group By with its formula and examples. You can download the template here to use it instantly.

Guide to What Is Tableau Group By. We learn how to do group by in Tableau with examples and points to note. You can learn more from the following articles –

Hierarchy in Tableau

Tableau Conditional Formatting

Tableau Functions

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *