2

I want to create a Calculated field to display a Number when the Column/Dimension Outcome_Code == Death.

EX: Out of 1000 rows if 400 rows has Outcome_Code == Death, then I just want to to display a big Number 400.

If I give COUNT(Outcome_Code == 'Death'), it is just just counting total number of rows in the table and showing 1000.

How to create a Calculated field in this case, I don't want a table of value counts, I Just want to display the number, so want a calculated field.

1 Answers1

1
SUM(INT([Outcome_Code] = "Death"))

The innermost expression is a boolean valued expression. The function INT() is a type conversion function that converts boolean values into integers -- evaluating to 1 if the boolean value is True and 0 if it is False. You can leave off the SUM in the calculated field and apply that on the shelf instead if you prefer.

It's worth the effort to realize that boolean expressions are first-class expressions, and can be treated just as naturally as numeric expressions. Other similar expressions are:

MAX([Outcome_Code] = "Death") 

which evaluates to True if ANY data records have "Death" for an [Outcome_Code]

and

MIN([Outcome_Code] = "Death") 

which evaluates to True if ALL data records have "Death" for an [Outcome_Code]

The last two take advantage of the fact that Tableau treats True as greater than False -- from which you can derive the meaning of MIN and MAX applied to boolean expressions

Alex Blakemore
  • 11,301
  • 2
  • 26
  • 49