2 Replies Latest reply on Mar 15, 2016 10:55 AM by vinutha vasanthu

    Which one to use "CASE" OR "IF"

    vinutha vasanthu

      I have following function/calculation which is performed in the SQL end. I want the same to be performed at the tableau end.

      CONVERT(datetime2,s.PolicyEffective) <= CASE WHEN SUBSTRING(s.WritingCompany,0,4) = 'GOT' THEN CONVERT(datetime2,'2014-6-1') ELSE CONVERT(datetime2,'2013-8-1') END

      I wrote the same in tableau as

      IF  [Writing company] = 'Gotham%' AND [Policy Effective Date]<='2014-6-1'THEN [Gross Premium]

      ELSEIF  [Writing company] = 'New York%'AND [Policy Effective Date]<='2013-8-1'THEN [Gross Premium]

      ELSE 0 END

      Not getting the correct expected results.

       

      Please clarify if the calculation i wrote is right or wrong.

        • 1. Re: Which one to use "CASE" OR "IF"
          Derrick Austin

          Hey Vinutha,

           

          You changed the logic a bit migrating it over. I'm unsure if this was intentional or not, but here is a version that is closer to the original logic:

           

          IF RIGHT(UPPER([Writing company], 4)) = 'GOT'

            THEN

            IF [Policy Effective Date] <= '2014-6-1'

            THEN [Gross Premium]

            END

          ELSEIF [Policy Effective Date] <= '2013-8-1'

            THEN [Gross Premium]

          END

          1 of 1 people found this helpful
          • 2. Re: Which one to use "CASE" OR "IF"
            vinutha vasanthu

            Hey Austin,

             

            This is the actual Query which i am trying to do in calculation

             

            SELECT Pre    

            FROM UMB_Pre  s

            WHERE s.Batch_ID = 1234

            AND s.Feed_ID = 'p10003'

            AND CONVERT(datetime2,s.Policy_Effective_Date) <= CASE WHEN SUBSTRING(s.Writing_Company,0,4) = 'Got' THEN CONVERT(datetime2,'2014-6-1') ELSE CONVERT(datetime2,'2013-8-1') END

             

            I also need to consider the batchID...so can i still use if else