Tableau count number of times same value appears in column

雨燕双飞 提交于 2020-01-01 09:23:29

问题


I have a field such that

Color
Pink
Blue
Pink
Blue
Pink
Pink
Pink
Pink
Pink
Blue
Blue
Pink
Pink
Pink
Blue
Pink
Blue
Pink
Blue

How to create calculated field to count number of times Pink appears?

Total numbers of Blue?


回答1:


If you're grouping by Color and only Color in the view, then you can simply use SUM(Number of Records). For example, put Color in the Rows shelf and SUM(Number of Records) into Text, and you'll get a table with the counts for each Color.

If you need to specify the level of detail, Tableau has LOD (level-of-detail) expressions that will make this easy.

{ FIXED [Color] : SUM([Number of Records]) }

That statement says to calculate the SUM() of [Number of Records] and to group by [Color], regardless of the level of detail in the view.


FYI, [Number of Records] is a calculated field that Tableau automatically tosses into every data source. Here's the code:

1

This simply places a 1 in every row of your partition. If you SUM() those ones, you'll get the number of records. So your LOD calculation could have just as easily been:

{ FIXED [Color] : SUM(1) }


来源:https://stackoverflow.com/questions/32725936/tableau-count-number-of-times-same-value-appears-in-column

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