How To Unlock Better Google Data Studio Segments Using “CASE”

Let’s say you’re viewing a bar chart of Google Ads conversions by month google data studio,

You want to know how brands are affecting campaign performance.

bar chart of conversions over timeImage by author, April 2022

You decide to add campaigns as a “breakdown dimension” so that you can see conversions by campaign.

That division doesn’t give you the result you hoped for:

Stacked bar chart with over 40 campaignsImage by author, April 2022

With dozens of campaigns across multiple accounts, this chart is too noisy to be useful.

So now what?

You can create a filter for brand campaigns.

However, this will filter out any non-brand campaign exposure – which you may not want to do.

Had it been supported, importing your labels from Google Ads would have solved the problem.

How can you create your segments in Data Studio, so you can have complete control over your visualizations and get better insights?

Answer: Case.

This CASE statement lets you group branded and non-branded campaigns into two separate segments:

New Fields screen showing CASE statement grouping campaigns in Data StudioScreenshot taken by author, April 2022

Using the above code, campaigns that do not contain a “brand” (or Dutch language “markname”) will be grouped as “non-brand”.

The end result is exactly what we expected: a stacked bar chart with the breakdown dimension showing conversion totals only for the “brand” and “non-brand” campaign groups.

Stacked bar chart of brand and non-brand campaign groups over timeImage by author, April 2022

The trend in this chart is clear: brand conversions have been steadily declining throughout the year.

That insight can now drive a strategy to address the issue.

If you’re frustrated and confused by using CASE to get custom segments in Data Studio, fear not.

This article will show you how to use CASE with confidence, and give you some examples that you can apply directly to your reports for better visualization.

case for case

It’s hard to discuss CASE expressions without getting a little technical, so let’s start W3 SchoolDefinition of CASE statement:

The CASE statement goes through the conditions and returns a value if the first condition is met (such as an if-then-else statement). Therefore, once the condition is true, it will stop reading and return the result.

If neither condition is true, it returns the value in the ELSE clause. It returns NULL if there is no ELSE part and no condition is true.

In other words, you define the conditions for your segment (“brand campaign” in the example above).

If the condition is met (the campaign name contains “brand”), it is included in the brand group. If the condition is not met (the campaign name does not contain “brand”), it is in the non-brand group.

If that parable sounds too simple, let’s take a look at a little More complex scenarios for using CASE From Google Data Studio’s help pages:

A common use of CASE is to create new categories or groups of data. For example, to group selected country values ​​into the Sales Area dimension, you can create a CASE expression like this:


When country (“USA”, “Canada”, “Mexico”) then “North America”
When country (“England”, “France”) then “Europe”
Other “Others”


In this example, the five different countries are consolidated into two separate continents, with the category “Others” to hold any additional countries.

A list of dozens or hundreds becomes a clean list of three.

Power of Data Studio CASE Expressions

Make busy charts simple, clear and focused using custom groups and segments.

Compilation of charts and tables before and after using custom fields with case statementsImage by author, April 2022

Using CASE expressions, you can:

  • rebuild label Used in your Google Ads account.
  • Group Google Ads campaigns by priority, target region, language, or theme.
  • Consolidate or customize the default dimensions in your data source (such as replacing the Google Analytics default channel grouping with custom channel grouping),
  • Compare the performance of a single keyword or asset to a group or category.

After learning some basic syntax and structure, you can create CASE expressions to solve your specific segmentation and classification challenges.

How to Use Case Expressions in Data Studio

Looking for step-by-step instructions for using Data Studio Case Expressions? look no further.

Here we’ll review how to add a case statement and set up a formula.

1. Create a Calculated Field

You’ll find this option in the lower-right side of the Data panel. Click the blue “Add Field” button.

showing the location of the picture Screenshot taken by author, April 2022

2. Enter and Save the Case Statement

Give your field a name, then enter a description in the formula box (more on that below).

screenshot of Screenshot taken by author, April 2022

A valid formula will show a small green arrow at the bottom of the formula box.

Then press “Save” (or “Update”) and “Done.” Leaving “Save” on yields exactly the result you’d expect, so don’t forget to click both buttons.

3. Add the field as a dimension to your chart

You’ll find your new field with the CASE statement in your list of available fields from the Data panel, and you can add it as a dimension to your chart.

The location of the dimension field in the data panelScreenshot taken by author, April 2022

You can edit the CASE expression at any time by clicking on it from the “Available Fields” section of the Data panel.

How to write your case statement

Now that you know how to add a CASE expression in Data Studio, let’s look at the syntax you’ll use to create your formula.

You will use the following components in the Formula box for your CASE statement:

  • Case (opens the thread).
  • when (describes the situation).
  • then (Describes the result when the condition is met).
  • Otherwise (Optional: Describes the result if the condition is not met).
  • end (closes the thread).

As you have already seen in this article, there are several ways to format a CASE statement.

Ultimately, you’ll want to find a “common denominator” that’s only true for the condition you’re defining “WHEN”.

Here are some examples of how you can set up the WHEN / THEN formula:

  • when [field] = “condition” then “result”
  • when [field] != “condition” then “no result”
  • when [field] IN(“Value A”, “Value B”, “Value C”) THEN “RESULT”
  • when REGEXP_MATCH([field]”.*condition*”) then “result”
  • when CONTAINS_TEXT([field]”condition”) then “result”

You can get much more advanced than this, but it should be enough to get you started.

Case limits and caveats

With the great power of CASE comes the great responsibility of making sure your data is really…accurate.

Here are a few things to look for and fix.

Aggregation errors and solutions

Your data source and metric aggregation method can cause charts to be inaccurate or broken, including:

  • Non-weighted Average of Average: mean mean Distorts actual performance metrics.
  • Average Metric Sum: Showing the total of the average is incorrect.
  • User configuration error: Some data sources will give a configuration error instead of displaying inappropriate aggregates.
Compiling Image of Possible Errors Using CASEImage by author, April 2022

Solution: Do not collect pre-calculated fields.

If you have a Count (CPC, AOV) instead of Raw Total (Cost, Session), here’s what to do instead:

Create a new Calculated field. Enter the formula, and swap the metric with your new field in your chart’s data panel.

New field screen showing cost/click formulaImage by author, April 2022

Segmentation Trap (Signal vs Noise)

There is no limit to how you can slice and dice the data, but there is a limit to how valuable certain data segments will be.

Correlation is not causation, and identifying trends is not as valuable as knowing causation.

So while you can segment your data by average CPC ranges, it’s the intent of the keyword, not the cost of the click, that drives post-click performance.

Make sure your volumes relate to the effect shown in your chart, or you’ll find yourself optimizing for noise rather than signal.

Other Limitations

CASE has other constraints.

for example:

  • CASE operates in sequential order. If a value meets the criteria for multiple categories, it will be included only in the first category listed in the CASE statement.
  • You cannot mix dimensions and metrics in the WHEN condition.
  • You cannot use a formula within a WHEN or THEN clause.
  • The CASE field you create is unique to the data source. If you need the same formula for multiple data sources, you will need to create new instances.

You’ll learn more about CASE using it, but knowing the limits means less time troubleshooting and searching help forums.


The CASE statement is a powerful way to group and split your data in Google Data Studio.

It’s not as simple as the drag-and-drop assembly you’re used to. But even that is not out of reach.

Learn the basic terms and syntax, and before you know it, it will become a useful tool in your visualization toolbox.

more resources:

Featured image: Arab Photos / Shutterstock

Source link

Leave a Comment