Tableau count number of times same value appears in column
Asked Answered
A

1

10

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?

Alkoran answered 22/9, 2015 at 20:9 Comment(1)
Why the vote to close it? I was googling this, and couldn't figure it out...Alkoran
C
10

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) }
Crawler answered 22/9, 2015 at 20:33 Comment(1)
Hello there! Will check this shortly.Alkoran

© 2022 - 2024 — McMap. All rights reserved.