Returning a dimension field from CASE statement
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: 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,