Datastudio “When contains” Calculated Filed

2019-08-16 18:05发布

问题:

Is there a posibillity to search for names in source?

CASE 
WHEN Source="facebook_instagram"  OR Source="facebook.com" OR Source="m.facebook.com" OR Source="instagram.com" OR Source="instagram" OR Source="l.facebook.com" OR Source="lm.facebook.com" OR Source="facebook" OR Source="de-de.facebook.com" Then "Social"
ELSE "Sonstige" 
END

Is there a way to select all facebook sources, without list them?

回答1:

You can certainly reduce the amount of code by using REGEXP_MATCH

For example

CASE
WHEN REGEXP_MATCH(Source, '.*facebook.*') OR REGEXP_MATCH(Source, '.*instagram.*') THEN 'Social'
ELSE 'Sonstige'
END


回答2:

Another option to get rid of some of the duplication is to use in. For your code that would result in something like:

CASE 
WHEN Source IN("facebook_instagram", "facebook.com", "m.facebook.com", "instagram.com", "instagram", "l.facebook.com", "lm.facebook.com", "facebook", "de-de.facebook.com") Then "Social"
ELSE "Sonstige" 
END