Quick Tip: instant calc building

by Caitlin Walsh

Sometimes, especially when working from an existing workbook or template, it is a pain to repeatedly create and type out long calculated fields.

Many people will already know about one time-saving feature for building calculated fields in Tableau.
You can drag existing fields from the Data pane or from the Row and Column shelves as you are building out a calculation, saving you time typing them out manually, and avoiding any spelling errors.  Simply hold Ctrl., drag and drop the required field into the 'Create Calculated Field' pane, and finish building out the rest of the calculation around it:

However, if you already know some of the calculated fields you want to build, there is a simple and repeatable way to do so.

First of all, identify some types of calculated field that you are likely to need a lot.
These are a few that have come up during our client projects:

It will often be useful to compare data from the most recent 2 years in a dataset dynamically, while knowing negative and positive difference from a target or forecasted figure can also be handy.  Even if I don't know the exact names of the fields that will come up in future datasets, I can be pretty sure that my future calcs will follow this same structure.

I can save any amount of these in a document or .txt file ready to use.

For the next step, we will just need to be sure that each example calc is preceded by a clear title with 2 forward slashes in front: this will become the name of the calc when it is brought into Tableau.

Next, copy and paste all the example calcs into one new calculated field; no need to name it, this is just our starting canvas:

Finally, all we need to do is drag the example calcs and their titles into the data pane one by one.
As we drag them left towards the data pane, their given titles (i.e. the text after the //) will appear, and they will become ready-to-use calculated fields:

If there are any fields in the calculations which need replacing, the new calc will have a red exclamation mark next to it, letting you know that it needs editing.

In this my 'difference from forecast' calcs,  'Value' and 'Forecast' do not exist in the Superstore dataset I am using; however, I can simply replace them with 'Sales' and 'Regional target' to get the calculation working as expected.

This method might also useful for when working through tutorials and other blogs online: simply save the necessary calcs into a file with a double-slash title, copy them all into a new calculated field, and start building...