Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tableau count number of times same value appears in column

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?

like image 231
Rhonda Avatar asked Sep 22 '15 20:09

Rhonda


People also ask

Can you Countif in Tableau?

Take SUMIF and COUNTIF as an example. Tableau has an IF function, a SUM function and a COUNT function, but not SUMIF or COUNTIF.

How do I count unique values in a column in Tableau?

Count Distinct – whose syntax is COUNTD (expression) - this function returns the number of distinct items in a group. Each unique value is only counted once. Note, NULL values are not counted.

What does countd mean in Tableau?

COUNTD() – This function will always return the number of UNIQUE values in the selected field. This means that if you have a field with two values 0 and 1 in a table with 100 rows, this function will return the value 2, unlike COUNT () where the result would be 100.


1 Answers

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) }
like image 53
Andrew LaPrise Avatar answered Sep 20 '22 19:09

Andrew LaPrise