1 Reply Latest reply on Mar 18, 2013 8:10 PM by Son Stegmaier

    Sales with included taxes as calculated field

    Mateusz Waligórski

      Hello Tableau Community,

       

      I am new to both SQL and Tableau. I am slowly figuring out ways to do good visualisations for my boss, but I have a diffculty converting one of his queries into a calculated field. It is a query that shows total sales including taxes, and I wanted to include it as a new Calculated Field.

       

      sum(

          CASE

          WHEN p.payType = 0 THEN

              (CASE WHEN ISNULL(a.price,pr.price) * 0.02 < 0.3 THEN ISNULL(a.price,pr.price) - 0.3 ELSE ISNULL(a.price,pr.price) * 0.98 END ) / 1.17

          WHEN p.payType = 1 THEN

              (pr.price * 0.53) / 1.23

          WHEN p.payType = 9 THEN

              (pr.price * 0.965) / 1.23

          WHEN p.payType = 10 THEN

              (pr.price * 0.77) / 1.23

          END

          ) AS sales_n_taxes

       

      At the moment I was trying to do a stripped version of it without the p.payType = 0 line, but it didn't work. Syntax error: Expected type float, found boolean. Comparison in 'CASE' must be float type.

       

      CASE [PPManager_products_revisions_price]

      WHEN [payType] = 1 THEN ([PPManager_products_revisions_price] * 0.53) / 1.23

      WHEN [payType] = 9 THEN ([PPManager_products_revisions_price] * 0.965) / 1.23

      WHEN [payType] = 10 THEN ([PPManager_products_revisions_price] * 0.77) / 1.23

      END

       

      I am probably asking something that is explained in one of the tutorials, if that's the case, sorry, I couldn't find a solution to this in tutorials Anyway, thanks in advance

        • 1. Re: Sales with included taxes as calculated field
          Son Stegmaier

          Welcome Mateusz!

           

          Without knowing what you are trying to accomplish, my best guess would be to try and remove [PPManager_products_revisions_price] from your case statement:

           

          CASE [payType]

          WHEN  1 THEN ([PPManager_products_revisions_price] * 0.53) / 1.23

          WHEN 9 THEN ([PPManager_products_revisions_price] * 0.965) / 1.23

          WHEN 10 THEN ([PPManager_products_revisions_price] * 0.77) / 1.23

          END

          Hope that helps.