3 Replies Latest reply on Dec 14, 2018 2:37 AM by Ben K

    Tutorial: How to write fast calculations in Tableau Desktop.

    Tyler Garrett

      Tutorial: How to write fast calculations in Tableau Desktop.

      Hello, here I would like to offer a quick - how to write fast calculations in Tableau Desktop.


      This particular Tutorial can be applied to a lot of posts being generated on the community Q/A.



      Color between Two months, May and April.  Two colors. What calculation works the best?

      Screen Shot 2017-12-04 at 12.53.49 PM.png


      Offer the best possible solution for the visualization above and explain calculations that can generate the same solution - but are not optimized for for speed or extract sizes.



      This will help the community leaders offer faster calculations - and will help others who don't comment, or ask questions -- a chance to use calculations that will not impact your workbook as much as others. I do believe explaining calculations multiple ways will show people how to be better at the product.


      How to write fast calculations in Tableau Desktop.


      if month(date)>=5 then "orange"

      elseif month(date)<=4 then "blue"

      else "filter out"


      // you don't need to tell an extract to keep track of a lot of strings because it makes everything slower, it makes the extract bigger, and it isn't going to help complex workbooks or large data sets. it will actually hurt the workbook if they want to 'FIND these colors' for later aggregation, which is generally always the case as they advance in their skills. also, this generates a lot of STRING manipulation in aggregation at a later date. Which generates super slow workbooks for no reason.



      if month(date)>=5 then "blue"

      else "orange"


      // else isn't necessary and 2 strings is slow.


      SLOW-ish CHOICE:

      if month(date)>=5 then "blue"


      // else converts to NULL vs asking the app to write ORANGE.


      A LITTLE FASTER: (using comments to explain what things need to be)

      if month(date)>=5 then 1 //blue

      elseif month(date)<=4 then 2 //orange

      else 0 //filter out


      // this is a step in the right direction, requires a lot less pain in the future because you're teaching them to use INTEGERS which databases prefer over STRINGS because there's only 0,1,2,3,4,5,6,7,8,9 choices, where strings have HUNDREDS of choices, and you're asking the database to effectively work more than necessary and complicating the calculations.



      if month(date)>=5 then 1 //blue

      else 0 //orange


      // just typing numbers, and commenting out strings would make this scalable for complex workbooks and bigger dataz.


      Pretty dang fast.


      // boolean flag.

      Screen Shot 2017-12-04 at 1.14.58 PM.png

      Write fast calculations in Tableau Desktop and grow the community!

      Writing fast calculations in Tableau Desktop is important for user adoption. Also, it will help grow the community to become great at native tableau desktop features. Eventually calculations need to be optimized - and this can be very complex in the future if there are hundreds of slow calculations.


      Hope this helps all the new peeps in the forums.


      Please start with --- https://www.tableau.com/learn/training