Video | Tableau | Data visualisation

How to write calculations clearly in Tableau: Desktop & Web authoring

Spell out your calculation logic as comments first, then test each piece live in the view before you ever combine it.

  • Plan your calculation first by writing out each step as comments, using double forward slash for single lines or /* */ for blocks
  • Build and test calculation logic one piece at a time before combining it, rather than writing one complex statement in one go
  • Drag a highlighted calculation directly onto Text or onto Rows/Columns to test it instantly as an ad hoc calculation, then double-click the pill to edit it in place
  • Format calculations by putting each new condition on its own line so the logic stays readable for whoever opens the workbook later
  • Ad hoc calculations used for testing can be deleted afterwards, or dragged to the data pane to save them as named fields

Writing good calculations are a must once you start to build more and more complex logic statements or once you start working in a team and you want your colleagues to be able to understand your work. In this video, I show you some key things you can do to streamline how you write your calculations.Source In0:00 Intro0:12 Setting up01:40 Get used to using comments in your calculations3:36 Writing and testing calculations5:05 Quickly test your calculation9:31 Format your calculations12:48 Turn ad-hoc calcs into proper calcs