CASE Statements In Google Data Studio

CASE statements allow you to create new dimensions in Google Data Studio based on existing ones. Syntax of CASE statement is pretty intuitively and reminds SQL a lot:

    WHEN condition THEN result
    WHEN condition THEN result
    ELSE result 

In order to create a new calculated field – open your Data Studio report, and click “Create new field”:

Give your new dimension a name, write your CASE statement in “Formuła” field and save it:

Data Studio CASE statement for Google Analytics Channel Grouping

That is an example of CASE statement for Channel Grouping in Google Analytics:

WHEN ((Source="direct" AND Medium="(not set)") OR Medium="(none)") THEN "Direct"
WHEN Medium="organic" THEN "Organic Search"
WHEN (Social Source Referral="Yes" OR REGEXP_MATCH(Medium,"^(social|social-network|social-media|sm|social network|social media)$")) THEN "Social"  
WHEN Medium="email" THEN "Email"
WHEN Medium="affiliate" THEN "Affiliates"
WHEN Medium="referral" THEN "Referral"
WHEN (REGEXP_MATCH(Medium,"^(cpc|ppc|paidsearch)$") AND Ad Distribution Network!="Content") THEN "Paid Search"
WHEN REGEXP_MATCH(Medium," ^(cpv|cpa|cpp|content-text)$") THEN "Other Advertising"
WHEN (REGEXP_MATCH(Medium,"^(display|cpm|banner)$") OR Ad Distribution Network="Content") THEN "Display" ELSE "(Other)"

An example of another CASE statement I used to create a new dimension for filtering purpose, based on Google Ads campaign name:

WHEN REGEXP_MATCH(Campaign, "brand.*") THEN "Brand" 
WHEN REGEXP_MATCH(Campaign, "generic.*") THEN "Generic"
WHEN REGEXP_MATCH(Campaign, "gdn.*") THEN "GDN"
ELSE "other"

More information and examples you can find on in Google official documentation:

Think of the possibilities
0 0 votes
Article Rating
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments