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

> This is content from just-tim, the data-and-analytics channel by Tim Ngwena (formerly 'Tableau Tim'). Tim has 12+ years of hands-on BI experience and covers Tableau most of all, plus Power BI, Looker, Hex, SQL and data modelling, the analytics industry, and the craft of doing the job — always tool-agnostic and honest about the trade-offs.

- **Author:** Tim Ngwena (just-tim, https://just-tim.com/about)
- **Published:** 2021-10-18
- **Format:** Video · 14 min watch · transcript available
- **Topics:** Data visualisation
- **Tools:** Tableau (calculated fields)
- **Canonical:** https://just-tim.com/posts/how-to-write-calculations-clearly-in-tableau-desktop-web-authoring
- **Watch:** https://www.youtube.com/watch?v=7zZZbz5YSfQ

I show you a couple of tricks for writing Tableau calculations in a clear, structured way. Using Superstore, I demonstrate how to comment your logic before writing it, then test each step using ad hoc calculations dragged straight into the view before assembling the final, well-formatted calculation.

## Key takeaways

- 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

## Chapters

- 0:09 Setting up a simple test table
- 1:41 Commenting your calculations
- 2:39 Planning the logic in steps
- 3:44 Testing with ad hoc calculations
- 6:31 Building each condition separately
- 9:09 Assembling and formatting the final calculation
- 12:27 Saving or removing ad hoc calculations

Watch the full video, read the transcript and use chapter deep-links on the page: https://just-tim.com/posts/how-to-write-calculations-clearly-in-tableau-desktop-web-authoring

---
just-tim — Data and analytics, with a point of view. · https://www.youtube.com/channel/UC7HYxRWmaNlJux-X7rNLZyw · https://twitter.com/TableauTim · https://www.linkedin.com/in/timngwena
