3 Replies Latest reply on Jun 27, 2016 11:22 AM by Derrick Austin

    Calculated Field - Multiple IF Statements?

    Owen Davenport

      I need to group some columns (A,B,C,D,R) using a calculated field for a filter under the following categories:

       

      C, D, ABR, ABCR, ABDR, ABCDR

       

      I'm trying this with an IF statement:

       

               IF [Class C] > 0 THEN 'C'

      ELSEIF [Class D] > 0 THEN 'D'

      ELSEIF [Class A] > 0

             OR [Class B] > 0

             OR [Class R] > 0 THEN 'ABR'

      ELSEIF [Class A] > 0

             OR [Class B] > 0

             OR [Class C] > 0

             OR [Class R] > 0 THEN 'ABCR'

      ELSEIF [Class A] > 0

             OR [Class B] > 0

             OR [Class D] > 0

             OR [Class R] > 0 THEN 'ABDR'

      ELSEIF [Class A] > 0

             OR [Class B] > 0

             OR [Class C] > 0

             OR [Class D] > 0

             OR [Class R] > 0 THEN 'ABCDR' END

       

      The problem with this is it only returns the first four filters (C, D, ABR).  Obviously this is because by the time it gets to ABR, it's already looped through all the possibilities and doesn't even bother with the last three. Is there a simple way to return each category so that it's exclusive from the one before?  If I could do multiple independent IF/END statements instead of using ELSEIF, that would be ideal, but Tableau doesn't seem to like that.