How to Use Group By in Tableau Calculated Field

Cody Schneider••7 min read

If you're coming from an SQL background, one of the first things you'll look for in Tableau is the GROUP BY clause. But you won't find it. This article explains how Tableau approaches data aggregation and shows you how to replicate - and go beyond - the functionality of SQL's GROUP BY using a powerful feature called Level of Detail (LOD) expressions.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Understanding the "GROUP BY" Concept in Data Analysis

Before diving into the Tableau way of doing things, let's quickly review what GROUP BY actually does. In SQL, the GROUP BY statement is used to group rows that have the same values in specified columns into summary rows. It's almost always used with an aggregate function like SUM(), COUNT(), AVG(), MIN(), or MAX() to perform a calculation on each group.

For example, if you have a table of sales transactions, you might use GROUP BY to answer a question like, "What are the total sales for each product category?"

Your SQL query would look something like this:

SELECT
  Category,
  SUM(Sales) AS TotalSales
FROM
  YourSalesTable
GROUP BY
  Category,

This query collapses all the individual transaction rows into single summary rows, one for each unique category, and calculates the sum of sales for that group. This is a fundamental operation in data analysis.

How Tableau Handles Grouping Automatically

Tableau is a visual analytics platform, so it handles grouping differently. It doesn't rely on written commands. Instead, it groups data based on the dimensions you place into your view (the "viz").

Think of it this way: dragging a dimension onto the Rows or Columns shelf is Tableau's equivalent of a basic GROUP BY.

Let's recreate the SQL query above in Tableau without any special calculations:

  1. Connect to your data source (we'll use the Sample - Superstore data that comes with Tableau).
  2. Drag the Category dimension from the Data pane onto the Rows shelf.
  3. Drag the Sales measure onto the Text card in the Marks pane.

That's it. Tableau automatically performs a SUM(Sales) and groups it by Category because that's the dimension you placed in the view. You'll instantly see a small table with the three categories (Furniture, Office Supplies, Technology) and their corresponding total sales.

This works wonderfully for visualizations, but what if you need to use that aggregated value - that "total sales per category" - in another calculation, regardless of what's in your view? That's where a simple drag-and-drop isn't enough, and where Level of Detail expressions come in.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Replicating GROUP BY with Level of Detail (LOD) Expressions

Level of Detail (LOD) expressions allow you to compute aggregations at a level of detail that is different from the level of detail of your visualization. In simpler terms, they let you create a calculation that is "fixed" at a certain grouping level, just like a GROUP BY clause, and then use that result anywhere you want.

There are three types of LOD expressions in Tableau:

  • FIXED: Calculates a value at the level of detail specified only by the dimensions listed in the formula. This is the most direct equivalent to SQL's GROUP BY.
  • INCLUDE: Computes an aggregation using the dimensions in the view plus any dimensions listed in the formula.
  • EXCLUDE: Computes an aggregation at a higher level than the view, subtracting a dimension from the calculation.

For replicating a GROUP BY clause, we will almost always be using the FIXED LOD expression.

Using FIXED LOD for GROUP BY Logic

The real power of FIXED is that it allows us to create a portable, reusable aggregated value. Let's dig in with some practical examples.

The syntax for a FIXED LOD is:

{ FIXED [Dimension 1], [Dimension 2], ... : AGGREGATE([Measure]) }
GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Example 1: Getting Total Sales per Category

Let's create the calculated field we talked about earlier: a field that always contains the total sales for its respective category.

How to Create the Calculated Field:

  1. Right-click anywhere in the Data pane and select Create Calculated Field.
  2. Name the field something descriptive, like Sales per Category (FIXED).
  3. In the formula box, enter the following:
{ FIXED [Category] : SUM([Sales]) }
  1. Click OK.

What Does This Formula Mean?

  • { ... }: The curly braces tell Tableau this is an LOD expression.
  • FIXED [Category]: This part is the "GROUP BY" clause. It tells Tableau: "For every unique value of 'Category'..."
  • : SUM([Sales]): This is the aggregation part. It completes the instruction: "...calculate the total sum of sales."

How to Use It:

Now you have a new measure in your Data pane. Let's see how it works. Create a new sheet and build a view showing sales for each Sub-Category.

  1. Drag Sub-Category to Rows.
  2. Drag the standard Sales measure to Text.
  3. Now, drag your new calculated field, Sales per Category (FIXED), right next to the SUM(Sales) column.

You'll notice something powerful. The SUM(Sales) column shows the sales for each individual sub-category. But the Sales per Category (FIXED) column shows the total sales for the parent category repeated for every sub-category row. For example, all sub-categories within "Technology" will show the same value: the total sales for the entire Technology category.

This is incredibly useful. You can now use this fixed value to do other calculations. For example, to find out what percentage of category sales each sub-category represents, you could create a new calculated field:

SUM([Sales]) / MAX([Sales per Category (FIXED)])

This kind of row-level calculation using pre-aggregated values is a primary reason why LOD expressions are so essential.

Example 2: GROUP BY Multiple Columns to Find a Customer's First Order

What if you need to group by more than one dimension? The logic is the same. Let's find the first date a customer ever placed an order.

The SQL equivalent would be:

SELECT
  Customer_ID,
  MIN(Order_Date) AS FirstOrderDate
FROM
  YourSalesTable
GROUP BY
  Customer_ID,

In Tableau, we create a new calculated field:

  • Name: Customer First Order Date
  • Formula:
{ FIXED [Customer Name] : MIN([Order Date]) }

Now you have a field that you can use across your entire workbook that contains each customer's first purchase date. You can use this to differentiate between new and returning customers. For instance, you could create a boolean field:

[Order Date] = [Customer First Order Date]

Dropping this into your view on the Color shelf would immediately highlight every customer's first order.

Best Practices and Common Pitfalls

Using LOD expressions is a game-changer, but there are a couple of things to keep in mind, especially when it comes to filters.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Understanding Context Filters

One of the trickiest parts of using FIXED LODs is their relationship with filters.

By default, FIXED LOD expressions are calculated before regular dimension filters are applied.

This means if you have a { FIXED [Category] : SUM([Sales]) } calculation and then filter your view to only show the "Technology" category, the calculation will still compute the sales for all categories in the background. If you want a filter to apply to your FIXED LOD calculation, you must make it a context filter.

To do this, simply right-click the filter on the Filters shelf and select Add to Context. The filter will turn from blue to gray, indicating it is now a context filter and will be processed before your FIXED LOD expression is calculated.

Maintain Performance

LOD expressions are powerful, but on extremely large datasets with high cardinality (many unique values in your dimensions), complex nested LODs can impact dashboard performance. Always start simple and test the performance as you build more complexity.

Final Thoughts

While Tableau doesn't have a syntax box for writing GROUP BY, you can achieve the same results - and much more - with its visual tools and powerful Level of Detail expressions. A simple drag-and-drop of a dimension into your view handles basic grouping, while FIXED LODs let you create reusable, table-scoped aggregations that open up a whole new world of analytical possibilities.

Learning the intricacies of LODs and context filters is a great example of how powerful BI tools can also come with a steep learning curve. At times, you just want a simple answer without needing to become an expert on calculation syntax. For this, we've designed Graphed to work like your own personal data analyst. Instead of figuring out formulas, you can simply ask, "What were our total sales per category last quarter?" and get an instant visualization, because our AI handles the complex logic for you.

Related Articles