Comment Your Code in Tableau!

Data

Comment Your Code in Tableau!

by Tim Costello

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!

More About the Author

Tim Costello

Analytics Consultant
3 Reasons Why You Should Want a Data Warehouse I hear a lot of reasons people avoid a data warehouse: It takes too long to build, data warehouse projects are expensive and often end ...
The Tableau Performance Checklist: Filtering – Avoid High-Cardinality Quick Filters The next item in our Filtering checklist is: “Avoid high-cardinality quick filters (multi-select or drop-down lists). ...

See more from this author →

Subscribe to our newsletter

  • I understand that InterWorks will use the data provided for the purpose of communication and the administration my request. InterWorks will never disclose or sell any personal data except where required to do so by law. Finally, I understand that future communications related topics and events may be sent from InterWorks, but I can opt-out at any time.
  • This field is for validation purposes and should be left unchanged.

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK