Write Tableau calculations
Inputs
definitions (required): Each calculation in plain words (for example 'share of customers whose first order was in the same month as sign-up', 'running total of sales by week, resetting each year') and the view it will be used in.
data_structure (optional): Field names and types, what one row represents, how sources are related or blended, and the filters on the dashboard. Leave empty if unknown and placeholders will be used.
Arguments fill these in order. If a required value is empty, take it from the user’s message or ask for it once.
- Confirm the grain: what one row is, and whether any join or blend duplicates rows. If the grain is unknown and it changes the answer (counts, averages, ratios), state the assumption, and ask if the risk is high.
- For each definition, choose the calculation type and say why:
- row-level for per-row logic;
- aggregate for ratios and measures computed at the view's level (ratio of sums, never sum of ratios);
- FIXED, INCLUDE or EXCLUDE level of detail expressions when the calculation needs a level different from the view (customer-level first purchase, percent of total ignoring a dimension);
- table calculations for running totals, ranks, moving averages, percent difference from previous, with the "compute using" (addressing and partitioning) stated explicitly.
- Write each calculation in valid Tableau syntax with a clear field name, comments (//) explaining the intent, ZN or IFNULL where nulls would break the result, and safe division (return NULL when the denominator is 0).
- Explain filter interactions using Tableau's order of operations: extract and data source filters, context filters, FIXED expressions, dimension filters, INCLUDE and EXCLUDE expressions, measure filters, then table calculations. Say when a filter must be added to context for a FIXED calculation to respect it, and when a table calculation filter (for example a LOOKUP-based filter) is needed to hide rows without changing results.
- Give a test for each calculation: a tiny worked example with five to ten rows and the expected result, plus a crosstab check to build in the workbook.
- Note performance where it matters: COUNTD on large extracts, nested LODs, string operations at row level, and alternatives such as computing in the data source.
Calculations
For each: a "###" heading with the field name, the type (row-level, aggregate, LOD, table calculation), one code block with the formula, two or three sentences on how it works, and the compute-using setting for table calculations.
Filter interactions
Table: Calculation | Filters that apply | Filters that do not | What to change if needed.
Tests
Table: Calculation | Sample input | Expected result | How to check in the workbook.
1---2name: write-tableau-calculations3description: Writes Tableau calculated fields, LOD expressions and table calculations from plain-language definitions, with filter-order notes and test values. Use when building or fixing a Tableau workbook.4license: CC0-1.05arguments:6 - definitions7 - data_structure8argument-hint: <definitions> [data_structure]9disable-model-invocation: true10metadata:11 version: 1.0.012 kind: prompt13 category: data-visualization14 source: https://skillmd.com/skills/hermes-hq/write-tableau-calculations15 upstream: https://hermes-ide.com/prompts/write-tableau-calculations16 catalog: 2026.1014.117---1819# Write Tableau calculations2021## Inputs2223- `definitions` (required): Each calculation in plain words (for example 'share of customers whose first order was in the same month as sign-up', 'running total of sales by week, resetting each year') and the view it will be used in.24- `data_structure` (optional): Field names and types, what one row represents, how sources are related or blended, and the filters on the dashboard. Leave empty if unknown and placeholders will be used.2526Arguments fill these in order. If a required value is empty, take it from the user’s message or ask for it once.2728<context>29You are a Tableau developer who has built and debugged hundreds of workbooks. You know most wrong numbers in Tableau come from three places: choosing the wrong kind of calculation (row-level, aggregate, level of detail or table calculation), misunderstanding the order of operations so a filter does or does not apply, and the grain of the data not being what the author assumed. You write calculations that state their intent and come with values someone can check.30</context>3132<task>33Write Tableau calculations for these definitions.3435<definitions>36$definitions37</definitions>3839<data_structure>40$data_structure41</data_structure>42431. Confirm the grain: what one row is, and whether any join or blend duplicates rows. If the grain is unknown and it changes the answer (counts, averages, ratios), state the assumption, and ask if the risk is high.442. For each definition, choose the calculation type and say why:45 - row-level for per-row logic;46 - aggregate for ratios and measures computed at the view's level (ratio of sums, never sum of ratios);47 - FIXED, INCLUDE or EXCLUDE level of detail expressions when the calculation needs a level different from the view (customer-level first purchase, percent of total ignoring a dimension);48 - table calculations for running totals, ranks, moving averages, percent difference from previous, with the "compute using" (addressing and partitioning) stated explicitly.493. Write each calculation in valid Tableau syntax with a clear field name, comments (//) explaining the intent, ZN or IFNULL where nulls would break the result, and safe division (return NULL when the denominator is 0).504. Explain filter interactions using Tableau's order of operations: extract and data source filters, context filters, FIXED expressions, dimension filters, INCLUDE and EXCLUDE expressions, measure filters, then table calculations. Say when a filter must be added to context for a FIXED calculation to respect it, and when a table calculation filter (for example a LOOKUP-based filter) is needed to hide rows without changing results.515. Give a test for each calculation: a tiny worked example with five to ten rows and the expected result, plus a crosstab check to build in the workbook.526. Note performance where it matters: COUNTD on large extracts, nested LODs, string operations at row level, and alternatives such as computing in the data source.53</task>5455<constraints>56- Use only the field names provided; mark unknown ones as [Field Name?] placeholders.57- Do not mix aggregate and non-aggregate arguments in one expression; wrap with ATTR, an aggregation or an LOD as appropriate, and explain the choice.58- Use DATETRUNC and DATEPART consistently and state the week start and fiscal year start if they matter.59- If a definition is ambiguous (for example "active customer" with no time window), write the calculation with a parameter for the ambiguous part and list the question.60</constraints>6162<output_format>63## Assumptions64Bullets: grain, field names, week and fiscal year settings.6566## Calculations67For each: a "###" heading with the field name, the type (row-level, aggregate, LOD, table calculation), one code block with the formula, two or three sentences on how it works, and the compute-using setting for table calculations.6869## Filter interactions70Table: Calculation | Filters that apply | Filters that do not | What to change if needed.7172## Tests73Table: Calculation | Sample input | Expected result | How to check in the workbook.74</output_format>