Comment Your Code in Tableau!

In my recent blog post, “Using Comments in Tableau,” I described how to create a comment that would display as a tooltip when you hover over a dimension or measure. There is actually another kind of comment that I think is equally useful - the calculated field comment.

Creating a Calculated Field Comment

It’s pretty simple to add a comment to a calculated field. Simply put two forward slashes in front of whatever text you want to save as a comment, and Tableau will ignore that text when it is evaluating the syntax of the calculated field.

The following screenshot shows a classic example of this kind of comment. The only tricky part here is deciding what you want to write in your comment. When I teach Tableau classes, I usually say that a comment is your way of communicating with the person that will come along after you and have to maintain your Tableau dashboards. Imagine that the dashboards you create are so successful that you get a huge promotion (it could happen!). The comments you leave in your calculated field will be the notes the next person needs to understand why you created this calculation in the first place. 

The important part is to comment your intentions. In other words, comment what you want your calculated field to do (and why), not HOW the calculation works. Hopefully, the next guy or gal will be able to see how it works for his or her self! :)

Calculated Field Comment

Inline Comments

Another way to comment your code is with inline comments. Here, you add a comment at the end of each line of your code. In the next screenshot, you’ll see where I used this technique to make a note that shows the city for each ZIP code I test for in my calculated field.

Inline Comment

Adding comments to your code can be a real time saver when you come back to work you did months (or years!) ago. If you don’t end up using them, it’s likely that the person who follows you will. Trust me, they’ll be grateful for any help you can give them!