How to Use CASE Function in Tableau

Cody Schneider8 min read

The CASE function in Tableau is one of the most practical tools for organizing your data exactly how you want it. It’s a clean and efficient way to create custom groups, reclassify messy data, or build new categories on the fly without changing your original data source. This article will walk you through what the CASE function is, its basic structure, and several real-world examples to help you start using it today.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

What is a CASE Function, Anyway?

Think of the CASE function as a neater, more organized version of a series of IF-THEN-ELSE statements. It looks at the values in a single field you specify and, based on what it finds, returns a corresponding result you define. It works like a sorting machine: if a record matches "Condition A," it goes into "Bin A", if it matches "Condition B," it goes into "Bin B," and so on.

So, when would you use it? The most common scenarios include:

  • Grouping countries into regions: Turning a long list of countries ('USA', 'Canada', 'Mexico') into tidy continent-level groups ('North America').
  • Categorizing sales performance: Bucketing products into performance tiers ('High Performer', 'Average', 'Underperformer') based on their category name.
  • Creating custom channel groupings: Consolidating messy UTM source data ('google', 'cpc', 'g-ads') into a clean 'Paid Search' channel.

The main advantage of CASE over a bunch of nested IF statements is readability. When you're checking a single field against a long list of possible values, a CASE statement is much easier for you (and your teammates) to read and debug.

The Basic Syntax

Every CASE statement follows a consistent and logical structure. Once you get the hang of it, you'll be writing them in seconds. Here is the basic template for a CASE function in Tableau's calculated field editor:

CASE [Your Field]
WHEN "Value 1" THEN "Result 1"
WHEN "Value 2" THEN "Result 2"
WHEN "Value 3" THEN "Result 3"
ELSE "Default Result"
END

Let’s break that down piece by piece:

  • CASE [Your Field]: This kicks things off. You tell Tableau which field (or "dimension") you want to evaluate. This could be [Country], [Product Category], or [UTM Source].
  • WHEN "Value": This is your condition. The statement looks for an exact match to the value you specify here. For example, WHEN "USA".
  • THEN "Result": If the WHEN condition is met, this is the output Tableau will return. For example, THEN "North America". You can have dozens of WHEN/THEN lines.
  • ELSE "Default Result": This is the optional but highly recommended "catch-all." If a value in your field doesn't match any of your WHEN conditions, it will be assigned this default result. It’s perfect for grouping all other values under a label like "Other" or "Uncategorized."
  • END: This simply tells Tableau that your CASE statement is finished. Don't forget it, or you'll get an error!
GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Practical Examples: Putting the CASE Function to Work

The best way to learn is by doing. Here are a few step-by-step examples that show how you can use the CASE function to solve common data analysis problems.

Example 1: Grouping Countries into Continents

Let's say your dataset includes a long list of individual countries, but for your dashboard, you want to show a map or bar chart summarizing sales by continent. A CASE statement is perfect for this.

The Goal: Create a new field called "Continent" from the existing "Country" field.

  1. Open the calculated field editor in Tableau (Analysis > Create Calculated Field).
  2. Name your new field something descriptive, like "Continent".
  3. Enter the following logic into the formula box:
CASE [Country]
WHEN "United States" THEN "North America"
WHEN "Canada" THEN "North America"
WHEN "Mexico" THEN "North America"
WHEN "United Kingdom" THEN "Europe"
WHEN "Germany" THEN "Europe"
WHEN "France" THEN "Europe"
WHEN "Japan" THEN "Asia"
WHEN "China" THEN "Asia"
ELSE "Other"
END

Click "OK," and you’ll see your new "Continent" dimension in the data pane. Now you can drag this field onto your sheet to instantly aggregate all your metrics (like Sales or User Count) at the continent level.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Example 2: Creating Custom Marketing Channel Groups

Pretty much every marketer has faced the chaos of UTM parameters. Your data might contain sources like "google," "t.co," "facebook.com," and "linkedin," but you want to report on broad channels like 'Paid Search,' 'Organic Social,' and 'Referral'.

The Goal: Clean up the [UTM Source] field and group it into clean marketing channels.

  1. Create a new calculated field and name it "Marketing Channel".
  2. Write a CASE statement to group the different sources. You can even combine it with other functions like CONTAINS() if you need more flexibility, but for direct matches, CASE is king.
CASE [UTM Source]
WHEN "google" THEN "Organic Search"
WHEN "bing" THEN "Organic Search"
WHEN "linkedin.com" THEN "Organic Social"
WHEN "facebook" THEN "Organic Social"
WHEN "t.co" THEN "Organic Social"
WHEN "mailchimp" THEN "Email"
ELSE "Direct / Other"
END

Now, instead of building a bar chart with 50 different traffic sources, you can build one with five clean channels, making it much easier to see which strategies are performing best.

Example 3: Categorizing Product Priority Level

Imagine you manage a product inventory. You have a [Category] field with values like "Essential Supplies," "Seasonal Goods," and "Speciality Items." You could use a CASE statement to assign a handling priority level to each.

The Goal: Label each product with a priority level based on its category.

  1. Create a new calculated field named "Handling Priority".
  2. Use the CASE function to assign a priority status to each product category.
CASE [Category]
WHEN "Essential Supplies" THEN "High Priority"
WHEN "Top Sellers" THEN "High Priority"
WHEN "Seasonal Goods" THEN "Medium Priority"
WHEN "Standard Stock" THEN "Normal Priority"
ELSE "Low Priority"
END

This calculated field lets you filter your dashboards to show only high-priority items or see your inventory broken down by handling needs.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

A Note on CASE vs. IF Statements

New Tableau users often wonder when to use a CASE statement versus an IF statement. They can sometimes accomplish similar things, but there's a key difference.

  • Use CASE for checking a single field against a list of exact matching values. This is what we did in all the examples above. It is simpler and faster for Tableau to compute in these scenarios.
  • Use IF for more complex logical tests. This is the right choice when you need to check for ranges of values (e.g., numbers greater than or less than something) or evaluate conditions across multiple fields at once.

For example, if you wanted to categorize sales deals into sizes ('Small', 'Medium', 'Large') based on their value, you couldn't use a simple CASE statement because you're dealing with numerical ranges, not exact values. You would need to use an IF...THEN...ELSEIF statement instead:

IF [Sales Value] < 1000 THEN "Small Deal"
ELSEIF [Sales Value] >= 1000 AND [Sales Value] < 5000 THEN "Medium Deal"
ELSEIF [Sales Value] >= 5000 THEN "Large Deal"
END

Remember this simple rule: Single field, exact values? Use CASE. Complex conditions or numeric ranges? Use IF.

Common Pitfalls and Quick Tips

As you get started, you might run into a few common issues. Here are some quick tips to help you avoid them.

  • Forgetting the END: This is the most frequent error. If Tableau gives you an error about an "unterminated" statement, check that you have an END at the close of your function.
  • Mixing Data Types: All of the results in your THEN statements must be the same data type. You can’t have one return a string ("High Performer") and another return a number (2). Make sure your outputs are consistent.
  • Handling Nulls: If a value is NULL in your original field, the CASE statement won't match any of your WHEN conditions. It will automatically fall into the ELSE bucket. This is another great reason to always include an ELSE clause to catch anything unexpected.
  • Case Sensitivity: Tableau's calculations are sensitive to capitalization. "USA" is not the same as "usa". To avoid issues, you can wrap your field in the LOWER() function to standardize it, like this: CASE LOWER([Country]) WHEN "usa" THEN ...

Final Thoughts

The CASE function is a fundamental building block for moving beyond basic charts in Tableau. By mastering it, you can take control of your data, cleaning up messy fields and creating new categories that help you tell a clearer story with your visualizations. It's a quick step that transforms your raw data into meaningful insights.

Of course, becoming proficient with tools like Tableau means learning syntax and spending time building calculated fields. Here at Graphed, we designed our platform to remove that friction completely. Instead of writing custom logic, our users connect their data sources and simply ask in plain English, "create a chart grouping sales by continent." Our AI handles all the underlying data transformations and visualizations, allowing your team to get from question to insight in seconds, not hours.

Related Articles

How to Enable Data Analysis in Excel

Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!