Datastudio “When contains” Calculated Filed

牧云@^-^@ 提交于 2019-12-11 17:23:30

问题


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


来源:https://stackoverflow.com/questions/54863979/datastudio-when-contains-calculated-filed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!