5 Replies Latest reply on Jun 14, 2018 3:36 PM by Arron Robles

    IF ELSEIF THEN Statement Help!

    Arron Robles

      Hello i am having issues with writing this statement. Can anyone assist me with favorable outcome? I Keep getting Calculation errors. Cannot mix AGG w/NonAGG comparisons in an if statement.

       

      IF [Emp Type] = "BAE1SMBSLS" and  [Position Tenurecount] = '0_3_Months' AND '4_6_Months' AND '7_12_Months'
      THEN sum([Data])+sum([Voice])+sum([Video])
      ELSEIF [Emp Type] = "BAE1SMBSLS" and  [Position Tenurecount] = '13_24_Months' AND '25_Plus_Months'
      THEN sum([Data])+sum([Voice])+sum([Video])
      ELSEIF [Emp Type] = "BAE3SMBSLS" 
      THEN sum([AV])
      else 0
      END 
      

       

       

      Cheers,

      Arron

        • 1. Re: IF ELSEIF THEN Statement Help!
          Vinnie Ahuja

          try putting attr() around [Emp Type] and [Position Tenurecount] in all of your IF/ELSEIF clauses

          • 2. Re: IF ELSEIF THEN Statement Help!
            Joe Oppelt

             

            IF [Emp Type] = "BAE1SMBSLS"

            and 

            ( [Position Tenurecount] = '0_3_Months'

            or  [Position Tenurecount] = '4_6_Months'

            or [Position Tenurecount] = '7_12_Months' )

             

            THEN sum([Data])+sum([Voice])+sum([Video]) 

             

            ELSEIF [Emp Type] = "BAE1SMBSLS"

            and 

            ( [Position Tenurecount] = '13_24_Months'

            or [Position Tenurecount] = '25_Plus_Months' )

             

            THEN sum([Data])+sum([Voice])+sum([Video]) 

             

            ELSEIF [Emp Type] = "BAE3SMBSLS"  

            THEN sum([AV]) 

            else 0 

            END  

            • 3. Re: IF ELSEIF THEN Statement Help!
              Joe Oppelt

              And yes.  Vinnie is right about ATTR() in the dimension fields.

              • 4. Re: IF ELSEIF THEN Statement Help!
                Chris McClellan

                Without testing in Tableau, I think you will need this:

                 

                IF attr([Emp Type]) = "BAE1SMBSLS" and ( attr([Position Tenurecount]) = '0_3_Months' OR attr([Position Tenurecount]) = '4_6_Months' OR attr([Position Tenurecount]) = '7_12_Months'  )
                THEN sum([Data])+sum([Voice])+sum([Video])  
                ELSEIF attr([Emp Type]) = "BAE1SMBSLS" and ( attr([Position Tenurecount]) = '13_24_Months' OR attr([Position Tenurecount]) = '25_Plus_Months' ) 
                THEN sum([Data])+sum([Voice])+sum([Video])  
                ELSEIF attr([Emp Type]) = "BAE3SMBSLS"   
                THEN sum([AV])  
                else 0  
                END  
                
                • 5. Re: IF ELSEIF THEN Statement Help!
                  Arron Robles

                  Hi Chris. This worked for me adding the ATTR() and removing the sum() form the statement fixed the issues.

                   

                  IF attr([Emp Type]) = "BAE1SMBSLS"

                  and ( ATTR([Position Tenurecount]) = '0_3_Months'

                  OR ATTR([Position Tenurecount]) = '4_6_Months'

                  OR ATTR([Position Tenurecount]) = '7_12_Months'  ) 

                  THEN [Data]+[Voice]+[Video]

                  ELSEIF ATTR([Emp Type]) = "BAE1SMBSLS"

                  and ( attr([Position Tenurecount]) = '13_24_Months'

                  OR ATTR([Position Tenurecount]) = '25_Plus_Months' )  

                  THEN [Data]+[Voice]+[Video]   

                  ELSEIF ATTR([Emp Type]) = "BAE3SMBSLS"    

                  THEN [AV]

                  else 0   

                   

                  Cheers,

                  Arron