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

# 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.

Usecase:

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

Goal:

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.

Idea:

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.

SLOWEST CHOICE:

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

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

else "filter out"

end

// 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.

SLOW CHOICE:

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

else "orange"

end

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

SLOW-ish CHOICE:

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

end

// 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

end

// 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.

A FASTER CALC:

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

else 0 //orange

end

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

Pretty dang fast.

month(date)>=5

// boolean flag.

# 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.

Best,

Tyler

Dev3lop

• ###### 1. Re: Tutorial: How to write fast calculations in Tableau Desktop.

HI Tyler,

Thank you for posting useful info.

I recommend that you move(re-post) this topic under this link.

Otherwise, this useful info will be gone under the big pile soon.

Regards,

Shin

1 of 1 people found this helpful
• ###### 2. Re: Tutorial: How to write fast calculations in Tableau Desktop.

I will add it over there tomorrow. I really appreciate the feedback. The forum is a bit challenging to keep up with and I try to keep it quick and simple when I'm here.

I appreciate it Shinichiro! Will write this down to things to do tomorrow.

Best,

Tyler

Dev3lop

• ###### 3. Re: Tutorial: How to write fast calculations in Tableau Desktop.

Good to know!

Thank you for sharing this.