4 Replies Latest reply on Aug 14, 2016 4:23 AM by siyang.teo

# Calculated Field Query: If else statement based on aggregated values of another column

Hi, I am trying to create a calculated field in Tableau using the example below.

Red is the desired output. It should give a "Y" for types of Species, e.g., Cat, when just one or more contains a Disease marked by "0".

Can anyone help? I am still pretty new to Tableau. Thanks!

• ###### 1. Re: Calculated Field Query: If else statement based on aggregated values of another column

Hi Siyang,

For future reference, it's much more helpful if you can upload a Tableau Packaged Workbook including sample data.

You should be able to get what you need by creating a calculated field like;

IF MIN([Disease])>0 then 'N' else 'Y' END

• ###### 2. Re: Calculated Field Query: If else statement based on aggregated values of another column

Hi Tom,

Thanks for the reply. Unfortunately that formula does not work as it computes based on just the disease column.

What I need is to compute it based on the species type. E.g., if just one cat have the disease, it means the infected values for all cat rows will be Y.

I have attached a twbx. Thank you in advance!

• ###### 3. Re: Calculated Field Query: If else statement based on aggregated values of another column

I can't open your twbx but will have a stab at this.

This formula should return a 1 or 0 for each species: {FIXED [Species]:MAX([Disease])}

That should be possible to modify to return a Y or N, perhaps this will do it: IF {FIXED [Species]:MAX([Disease])} = 1 THEN 'Y' ELSE 'N' END

• ###### 4. Re: Calculated Field Query: If else statement based on aggregated values of another column

So that's how Tableau's LOD calculation is used. Thanks a million Watson!