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:

CASE
    WHEN condition THEN result
    WHEN condition THEN result
    ELSE result 
END

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:

CASE
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)"
END

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

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

More information and examples you can find on in Google official documentation:
https://support.google.com/datastudio/answer/7020724?hl=en

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