4 Replies Latest reply on Dec 23, 2018 12:21 PM by Ken Flerlage

    Custom SQL: IF ELSE Statement

    Sai Sri B

      Hi Team,


      I see below error with IF ELSE statement when connected to xls as a source.

      Is there any issue in my syntax, please advise


        • 1. Re: Custom SQL: IF ELSE Statement
          Ken Flerlage

          Despite the error, Tableau is not having trouble connecting to the file. Rather, the syntax of your SQL is invalid, causing it to fail. For instance, if you try a simple SQL such as the following, it will work fine:

          IF logic like that is not part of SQL. Generally, you'd use a CASE statement, but I tried that and it doesn't appear to work with Excel either. I'm not entirely sure how Tableau is allowing custom SQL against Excel, but my guess is that it does not support the full array of SQL functionality.

          • 2. Re: Custom SQL: IF ELSE Statement
            Ken Flerlage

            I should also note the following, according to Tableau (Connect to a Custom SQL Query - Tableau):


            IMPORTANT: Starting in Tableau 2019.1, you will no longer be able to create a new Legacy Excel or Text connection. Existing workbooks created with these legacy connections will continue to work until 2019.2, when all support for legacy connections will be removed. See the Legacy Connection Alternatives document in Tableau Community for alternatives to using the legacy connection.


            So, you should really consider not trying to use custom SQL with Excel. Something like what you're trying to do could be easily done within a calculated field instead.

            • 3. Re: Custom SQL: IF ELSE Statement
              Naveen B

              Hi Sai Sri,


              Since you are connecting to excel you need to use jet database if clause instead of normal if clause


              change  if clause like below



              Hope this helps,

              Plz Mark this answer as correct or helpful to close the thread




              3 of 3 people found this helpful
              • 4. Re: Custom SQL: IF ELSE Statement
                Ken Flerlage

                I didn't realize this Naveen! Good to know.


                Still probably best not to use legacy connections to Excel considering the upcoming de-support.

                1 of 1 people found this helpful