6.8. Returning Expressions in Looker Studio CASE Functions
In this lesson we will see CASE(), CONTAINS_TEXT(), and REGEXP_EXTRACT() functions applied to return expressions in Looker Studio.
In the CASE function, you can return dynamic values or expressions instead of static, literal values. This allows for more complex and customized output based on the conditions being evaluated.
Example
In this example, you want to extract the product title that comes directly after the product brand. Instead of returning a static value for the brand name, you want to extract the part of the product title that comes after the brand name.
You can use the REGEXP_MATCH() and REGEXP_EXTRACT() functions along with the CASE function to achieve this:
CASE
WHEN CONTAINS_TEXT(product_title, 'Google Cloud') THEN REGEXP_EXTRACT(product_title, 'Google Cloud (.*$)')
WHEN CONTAINS_TEXT(product_title, 'Google') THEN REGEXP_EXTRACT(product_title, 'Google (.*$)')
WHEN CONTAINS_TEXT(product_title, 'YouTube') THEN REGEXP_EXTRACT(product_title, 'YouTube (.*$)')
WHEN CONTAINS_TEXT(product_title, 'Android') THEN REGEXP_EXTRACT(product_title, 'Android (.*$)')
END
In this example, the REGEX_EXTRACT function is used to match the pattern and extract the part of the product title that comes after the brand name. The CASE function then returns the extracted product title as a dynamic value based on the matched condition.
📩 Receive my weekly Looker Studio tips
🎥 Subscribe to my YouTube channel
🖇 Connect with me on LinkedIn