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.

Watch on YouTube
  • 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

Tim shows a structured way to write and test Tableau calculations: plan the logic as comments first, then build and test each piece live in the view before combining it into one clean, well-formatted calculation.

Using Superstore, Tim builds a simple table (category, sub-category, segment) with no measure on text, so results stay easy to read. He then writes a calculation that tags furniture chairs as discontinued and everything else as discounted.

The Breakdown
  1. Comment your calculation before writing it 1:41

    Use double forward slash for single-line comments or /* */ to comment out a block. Commented text doesn't affect validity, so you can sketch logic freely before writing any real code.

  2. Plan the logic out as numbered steps 2:39

    Write each stage of what you want to achieve as its own comment line (e.g. step one, find X; step two, find Y) before touching the actual formula. This gives you a map to fill in underneath.

  3. Write each piece of logic under its comment 3:42

    Add a real calculation beneath each comment, spacing them out so they're easy to scan. Keep each piece self-contained so it can be tested independently before anything is combined.

  4. Test each piece live using ad hoc calculations 5:01

    Highlight a calculation and drag it straight onto Text, or onto Rows/Columns, to see it evaluate instantly as an ad hoc calculation in the pane. Double-click the resulting pill to edit it in place, which is a fast way to iterate without opening and closing the calculation editor repeatedly.

  5. Build up conditions one at a time 6:31

    Test the first condition, then write and test the next condition separately (double-commenting out the previous one so only one is valid at a time), placing each result next to the others in your test table. This trial-and-error approach in a simple table catches problems early, before the logic becomes a complex nested statement.

  6. Assemble the final calculation with clear formatting 9:09

    Once each piece works, strip out the comments and combine them into one statement, putting each new condition (if, and, else, end) on its own line. This formatting doesn't affect how the calculation runs, but makes it far easier for you or someone else to read later; Tim also restores a summary comment at the top explaining what the finished calculation does.

  7. Clean up or keep your ad hoc calculations 12:27

    Ad hoc calculations used purely for testing can simply be removed from the view once you're done. To keep one, drag it into the data pane and name it there — Tableau treats it as a saved field and updates the pill in the view to match.

Worth Knowing
  • Tableau doesn't autocomplete field or string values inside calculations, so misspellings (e.g. category names) will silently fail to match rather than throwing an error.
  • Leaving out an ELSE clause doesn't invalidate a calculation — unmatched rows are simply returned as null, which is useful for isolating one condition at a time.
  • Formatting (spacing, new lines) never breaks a calculation's logic, so there's no downside to spreading conditions across multiple lines for readability.
  • Dragging a highlighted calculation onto Text/Rows/Columns only works for calculations valid enough to evaluate; this is why testing pieces separately before combining is more forgiving than writing one long statement in one go.
Use It When

Reach for this whenever you're about to write a calculation with more than one condition — it keeps the logic auditable as you build it and leaves a readable trail for anyone (including future you) opening the workbook later.

How this Rollup was made provenance & method

A Rollup is drafted by AI from the video's transcript, then reviewed and edited by Tim. Everything used to produce this one is listed below — the model, the exact prompt, and the source video — so the process is transparent and reproducible.

Transcription
On-device — NVIDIA Parakeet v3 for recent videos, OpenAI Whisper large-v3 for earlier ones. The transcript never leaves the machine or gets published.
Drafting
Claude Sonnet 5 in the cloud, from that transcript.
Prompt
The exact Rollup prompt (v2) — the full system prompt, unedited.
Source video
Watch on YouTube
Drafted
5 July 2026 at 09:38
Reviewed & edited
5 July 2026 at 09:41 · by Tim Ngwena

Model + prompt + video is everything you'd need to recreate a Rollup like this yourself. The one thing we don't share is the transcript.

Rights. The video and its transcript are the property of TN Media Ltd. Unauthorised use or download is prohibited. © TN Media Ltd.