Datastudio “When contains” Calculated Filed

2019-08-16 17:59发布

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?

2条回答
趁早两清
2楼-- · 2019-08-16 18:14

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
查看更多
唯我独甜
3楼-- · 2019-08-16 18:22

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
查看更多
登录 后发表回答