【问题标题】:Number of Occurrence of a Substring in TableauTableau 中子字符串的出现次数
【发布时间】:2020-11-26 17:11:17
【问题描述】:

我有一列用逗号分隔一些单词。我想像这样计算每个单词的出现次数-

animals      count_cats  count_dogs
cats             1           0
cats,dogs        1           1
dogs,cats,dogs   1           2

如何在 Tableau 中实现这一点?

我按照此处的说明创建了一个计算字段 - https://kb.tableau.com/articles/howto/counting-occurrences-of-a-string-within-a-dimension - 但由于 CONTAINS 函数返回 True 或 False,这将返回 1 或 0。

提前致谢。

【问题讨论】:

    标签: tableau-api


    【解决方案1】:

    你可以这样做。

    对于count_dogs,请改用此计算

    (LEN([Animals])-
    LEN(REPLACE([Animals], 'dogs', '')))/
    LEN('dogs')
    

    您还可以使用以下计算进行参数计数(param 是参数)

    (LEN([Animals])-
    LEN(REPLACE([Animals], [param], '')))/
    LEN([param])
    
    

    【讨论】:

    • 很高兴它有帮助。请按照 SO 的要求投票。
    猜你喜欢
    • 2010-10-20
    • 1970-01-01
    • 2020-02-21
    • 2012-02-12
    • 2011-01-11
    相关资源
    最近更新 更多