Skip to content (Press Enter)

Looker Studio Tuto

Blog de Louis Dubruel

  • English
    • Français
  • I help you with your Looker Studio ↗️
  • English
    • Français
  • I help you with your Looker Studio ↗️

CASE WHEN function in Data Studio

by Louis Dubruelupdated on November 17, 2021November 17, 2021

One of the most used functions in calculated fields: the famous CASE function! You can use it to segment all types of data.

CASE function

Use

The CASE function allows related data to be grouped together under certain conditions.

The syntax of the function is as follows:

CASE 
    WHEN ... THEN "..."
    WHEN ... THEN "..." 
    ELSE "..." 
END
  • WHEN is a condition. It accepts many functions like the 3 REGEXP functions and logical operators.
  • THEN is the expected result if the data respects the associated condition (this will be your data group)
  • ELSE is the mandatory fallback that will collect all the data that do not respect the conditions defined by WHEN
  • END is mandatory

Note that the system reads CASE statements from top to bottom. If a data item respects 2 WHEN conditions, then it will only be captured by the 1st one in the reading order from top to bottom.

In the following case, all “URL” data are captured by the first condition i.e. Group 1. Group 2 and Group 3 will be empty (null value on Data Studio)

CASE 
WHEN REGEXP_MATCH(URL,"https://www.my-site.com/." THEN "Group 1" 
WHEN REGEXP_MATCH(URL,"https://www.my-site.com/categorie.") THEN "Group 2" 
ELSE "Group 3" 
END

Applications

Segment URLs with the CASE function and the REGEXP_MATCH function

Calculate field:

CASE 
    WHEN REGEXP_MATCH(URL,".*/tag/.*" THEN "Tags"
    WHEN REGEXP_MATCH(URL,"(.*/product/.*|.*\\.html$)") THEN "Product pages" 
    ELSE "Autre pages"
END

Useful with data sources:

  • Google Analytics – Dimension “Pages
  • URLs de la Search Console – Dimension “Landing page”
  • Google Ads – Dimension “Landing page”

Create average position segments

Calculate field:

CASE 
    WHEN Position = 1 THEN "Top 1" 
    WHEN Position < 4 THEN "Top 3" // so from 1,0x to 3,9x
    WHEN Position < 10 THEN "Top 10" // so from 4,0x to 9,9x    
    ELSE "10+"
END

Note that I start with the smallest position since the syntax is read from top to bottom.

Useful with the Search Console data source!

Apprendre Google Data Studio

Louis Dubruel

Post Navigation

Previous Article
Next Article

Formation & templates

Obtenez mon wiki Looker Studio
Découvrez votre User Journey moyen avec ce template !
Découvrez mes templates de dashboards

  • SEO analytics: analyse your keyword trends like in SEMRush on Data Studio
  • How to create a Cohort analysis in Google Data Studio
  • JOIN in Data Studio
  • CASE WHEN function in Data Studio
  • When are pie chart most effective ?

©️Louis Dubruel 2020-2025

When are tree maps most effective?
Recommended for you...

When are tree maps most effective?

by Louis Dubruel
Recommended for you...

Growth Rate: Calculate and visualize it in Data Studio

by Louis Dubruel
Recommended for you...

JOIN in Data Studio

by Louis Dubruel
© Copyright 2025 Looker Studio Tuto. All Rights Reserved. The Ultralight | Developed By Rara Theme. Powered by WordPress.