When creating calculated fields in Tableau it’s important to comment the calculated fields. Especially complex calculations where it may not be immediately obvious why the calculation exists or what the calculation does.
If another Tableau developer picks up your work they need to understand what your calculated fields should do.
How to add comments to a calculated field in Tableau
Comments are simple to put into a calculated field. Just start a line in the calculated field with two forward slashes //
Everything typed after the // on the same line is a comment.
As of Tableau 2020.4, commenting has become even better. As well as the single line comments //, from 2020.4 Tableau supports multi-line comments.
Similar to some programming languages, such as SQL, using /* and */ is a way to write multi-line comments in Tableau.
Adding comments to your calculated fields is important, especially for more complex calculations.
In the example above, SUM([Sales]), it’s less important as this should be obvious to any developer what it is doing.
But if your calculation is long or written for a specific purpose then you should add comments giving some explanation.
This is important when your work is handed to someone else.
Even for your usage including comments is useful. Especially when it’s a calculation not often used, so you lose familiarity around why you wrote it in a certain way.
If it takes you longer to decipher how a calculation works than it took to initially write the calculation, you consider comments.
Be explicit and generous in your comment usage.
You don’t want to spend 30 mins trying to work out what your own calculation does when you need to alter existing workbooks!
Plus perhaps someone else will want to look at it one day, it would help them to include a description.