When I was building a Tableau dashboard for sales analysis, I faced a situation where the Sub-Category field had too many detailed values, such as Chairs, Tables, Bookcases, and Furnishings, etc.
As a solution for this, I used a CASE statement to group them into simple categories like Seating, Storage, and Other. By using the CASE function in a formula, I was able to filter out the sub-categories we want to focus on while still keeping the rest of them.
In this tutorial, I’ll explain how to use a CASE statement in Tableau with the help of examples.
Case Statements in Tableau
In Tableau, a CASE statement is a type of calculated field that functions like an “if-then” condition, allowing us to test conditions and return specific results. Instead of writing multiple IF statements, we can use CASE to check a field for different values and assign an output.
For example, we can use a CASE statement to classify subcategories into custom groups like Seating, Furnishing, and Other. It makes calculations easier to maintain when we’re working with multiple conditions.
Use a Case Statement in Tableau
In this example, we will use a CASE statement to group Sub-Categories into custom groups. For example, we’ll put chairs and tables in Seating, Bookcases and Furnishings in Storage, and the rest into the Other group.
Now connect the Tableau with the Superstore data set and follow the steps below to see how we can use the CASE statement in Tableau.
- Create a bar chart to show the subcategory sales, and for this, drag Sub-Category to Columns and Sales to Rows.

- Now, we will create a calculated field using the CASE statement. For this, click on the Analysis tab and select Create Calculated Field.

- Enter the Name for the calculated field and enter the formula below to group the sub-category, and click OK.
CASE [Sub-Category]
WHEN "Chairs" THEN "Seating"
WHEN "Tables" THEN "Seating"
WHEN "Bookcases" THEN "Storage"
WHEN "Furnishings" THEN "Storage"
ELSE "Other"
END
- Now, add the calculated field “Product Analysis” to the Columns. With this, sub-categories will be grouped in the Seating, Storage, and Other.

- For a better comparison view, drag the calculated field in the Color card. This will assign a different color to each group that we have created.

- To remove the calculated field column from the chart, right-click on the label and select Hide Field Labels for Columns.

- At last, click on the Text icon in the navigation bar to show sales for the grouped values in the bar chart.

This way, we can use the CASE statement to create a calculated field that can be used as a dimension, which we can add to Rows, Columns, Filters, Color, or even use in another calculated field.
Use Case Statement with Multiple Conditions in Tableau
In Tableau calculated fields, we can also use nested CASE statements with multiple conditions to define complex logic using a calculated field.
In this example, we will use a nested CASE statement with multiple conditions to group the Ship mode into two categories. In this, we will divide it into two categories: Fast shipping and Regular shipping, to analyze Sales from both groups.
Now, follow the steps below to create and use the calculated field using the CASE statement with multiple conditions.
- To create the calculated field, click on the Analysis tab -> Create Calculated Field.

- Enter the label for the calculated field as “Shipping Group,” enter the formula below, and click OK.
CASE [Ship Mode]
WHEN "First Class" THEN "Fast Shipping"
WHEN "Same Day" THEN "Fast Shipping"
WHEN "Second Class" THEN "Regular Shipping"
WHEN "Standard Class" THEN "Regular Shipping"
ELSE "Other"
END
The above CASE formula categorizes the Ship Mode field into groups: First Class and Same Day are assigned to Fast Shipping, then Second Class and Standard Class are assigned to Regular Shipping, and all other options are labeled as Other.
- Now add the calculated field Shipping Group to the Rows and Sales to the Columns.

Now, we can see the groups that we have divided in Shipping mode categories using the CASE statement.
- In this grouping, First Class and Same Day are assigned to Fast Shipping, then Second Class and Standard Class are assigned to Regular Shipping. To view all values in the bars, we can add the ship mode to the column or in the color card for the stacked chart view.

This way, we can use a CASE statement with multiple conditions in Tableau and show multiple detailed values in simplified categories.
Conclusion
In this Tableau tutorial, we learned how to use the CASE statement in Tableau to group values into simple categories. In the above examples, we have used a CASE statement in the formula field by grouping sub-categories.
Then, in the next example, we used the nested CASE statement with multiple conditions to create custom groups like Fast Shipping and Regular Shipping.
By following the above example, you can use CASE statements in Tableau calculated fields and use them in charts, tables, or dashboards to group data and apply conditions.
You may also like to read:
- Create a Table in Tableau
- Repeat Row Labels in Tableau
- Show Top N Results in Tableau Chart
- Sort Values in Tableau Stacked Bar Chart
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.