Back
I have a field such that
ColorPinkBluePinkBluePinkPinkPinkPinkPinkBlueBluePinkPinkPinkBluePinkBluePinkBlue
Color
Pink
Blue
How to create calculated field to count number of times Pink appears?
Total numbers of Blue?
If you want to group by color and only Color in the view, then you can simply use SUM(Number of Records). Let us look at an 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 want 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, i.e[Number of Records] is a calculated field that Tableau automatically tosses into every data source. Here's the code:
1
This would place 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) }
You can enroll in this Best Tableau Certification course online by Intellipaat to learn basic and advanced Tableau.
31k questions
32.8k answers
501 comments
693 users