如果单元格中的字符串包含 X,则创建自定义维度

Create custom dimension if string in cell contains X

我正在尝试在 Google 数据工作室中创建自定义维度。维度应检查单元格字符串是否包含特定字符串和 return 另一个字符串。

我一直在谷歌搜索,我发现我需要使用带有 regex_match 的 case 语句,但我无法判断我是否正确地完成了它,因为结果字段被选为自定义指标而不是自定义维度

这些是我的活动名称:

bil_ May-June'19_ Tertiary Campaign_ BMM_24th May'19
bil_ May-June'19_ Category Campaign_ BMM_24th May'19
bil_ May-June'19_ Brand Campaign_ BMM_24th May'19
bil_ May-June'19_ Category Campaign_ Exact_24th May'19
bil_ May-June'19_ Brand Campaign_ Exact_24th May'19
bil_ May-June'19_ Tertiary Campaign_ Exact_24th May'19

这是我写的对它们进行分类的案例陈述:

CASE 
    WHEN REGEXP_MATCH(CAMPAIGN,".*Tertiary.*") THEN "Tertiary"
    WHEN REGEXP_MATCH(CAMPAIGN,".*Brand.*") THEN "Brand"
    WHEN REGEXP_MATCH(CAMPAIGN,".*Category.*") THEN "Category" 
    ELSE "Other"
END

预期结果是一个只有 3 行(第三行、品牌和类别)的自定义维度。现在我不知道我是否正确地执行了此操作,因为该字段最终出现在指标列表中而不是维度列表中。

请大家帮忙!

测试了 CASE statement above, and it works as expected; ensure that the Type is set to Text, and if it's added as a Chart-level calculated field, add it as a Dimension (not a Metric); also, in this scenario, a single REGEXP_EXTRACT 函数的作用:

REGEXP_EXTRACT(CAMPAIGN, ".*(Tertiary|Brand|Category).*")

Google Data Studio Report和GIF详解: