AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Data Studio
5K members online now
5K members online now
Ask questions about Data Studio
Guide Me
star_border
Reply

Returning a dimension field from CASE statement

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I have a number of custom source strings that I want to aggregate into a single string via a new dimension in Data Studio. However as a default I would like to keep the "standard" source string.

 

I.e. if I have

  • source: foo_one
  • source: foo_two
  • source: bar_one
  • source:three_bar
  • source: google
  • source: email

 

I want this to be aggregated into "foo", "bar", "google" and "email" respectively.

 

I was trying to do the obvious and return the original built-in source dimension in my case statement after I matched my custom strings via regex:

 

CASE WHEN REGEXP_MATCH(Source, ".*foo.*") THEN "FOO" WHEN REGEXP_MATCH(Source, ".*bar.*") THEN "BAR" ELSE Source END

 

However that does not seem to work, the "ELSE" clause returns an empty value (but if I use a string value the case statement works).

 

This puzzles me a bit, since the documentation states that the "CASE statement can return [...] dimension fields".

 

Is this a bug or am I doing something wrong here ?

 

Thank you for your time,

 

Eike

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Eike P
December 2016

Returning a dimension field from CASE statement

Follower ✭ ☆ ☆
# 2
Follower ✭ ☆ ☆

Hey Eike,

 

Give this a go:

 

CASE WHEN REGEXP_MATCH(Source, ".*foo.*") THEN 'foo' WHEN REGEXP_MATCH(Source, ".*bar.*") THEN 'BAR' WHEN REGEXP_MATCH(Source, ".*") THEN Source END

 

Cheers,

 

Eddie

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Eike P
December 2016

Returning a dimension field from CASE statement

Follower ✭ ☆ ☆
# 2
Follower ✭ ☆ ☆

Hey Eike,

 

Give this a go:

 

CASE WHEN REGEXP_MATCH(Source, ".*foo.*") THEN 'foo' WHEN REGEXP_MATCH(Source, ".*bar.*") THEN 'BAR' WHEN REGEXP_MATCH(Source, ".*") THEN Source END

 

Cheers,

 

Eddie

Returning a dimension field from CASE statement

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Wonderful, works like a charm. Thank you very much !