Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in BI by (17.6k points)

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? 

closed

1 Answer

+1 vote
by (47.2k points)
selected by
 
Best answer
  • 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. 

Browse Categories

...