Create a Tableau calculated field: verify calculation level and aggregation
A Tableau calculated field is a reusable formula that combines source fields to define new values, categories, or ratios. Before writing it, decide whether the result is needed per source row, at the view’s aggregate level, or between values already in the view, such as a rank or running total. Ratios are especially easy to misinterpret: summing row-level ratios is not the same as dividing totals. Saving a formula does not prove it matches the intended metric.
A Tableau calculated field is a reusable formula that combines source fields to define new values, categories, or ratios. Before writing it, decide whether the result is needed per source row, at the view’s aggregate level, or between values already in the view, such as a rank or running total. Ratios are especially easy to misinterpret: summing row-level ratios is not the same as dividing totals. Saving a formula does not prove it matches the intended metric.
This guide reflects Tableau Cloud, Desktop, and Server Help reviewed on 19 November 2026. Menus and supported functions may vary by connector and environment. Get started with Tableau calculations · Choose a calculation type
Choose the calculation type first
| Question | Starting point | Example and caution |
|---|---|---|
| Transform or classify each source row? | Basic row-level calculation | Discount ratio per order. Tableau may aggregate it again when placed in a view. |
| Summarize a metric by current view dimensions? | Aggregate calculation | SUM(Profit) / SUM(Sales). Define what zero or null denominators mean. |
| Calculate at a level different from the source or view? | LOD expression: FIXED, INCLUDE, EXCLUDE | Calculate an order-level distribution even when the view shows only region. |
| Rank, running total, moving average, or previous-period comparison from values in the view? | Table calculation | RANK, RUNNING_SUM, LOOKUP, WINDOW functions. Addressing and partitioning affect the result. |
Tableau’s decision guide first asks whether all needed values are already in the visualization. If they are and the calculation depends on ordering, ranking, recursion, moving windows, or inter-row comparison, a table calculation may fit. If required source values are absent, use a basic calculation or LOD. If the question’s grain differs from both the source and view grain, consider LOD. Treat this as a starting rule and also check the data model and filters. Calculation-type decision guide
Create the field
In a worksheet, select **Analysis > Create Calculated Field**.
Give it a name that explains purpose and level, such as “Profit Ratio — total profit / total sales.”
Enter the formula. Drag fields from the Data pane or use autocomplete and the function reference. Check argument types, null behavior, and calculation order in the official reference.
Confirm the formula is valid and click **OK**. Tableau marks calculated fields with an equals sign beside the data-type icon in the Data pane.
Add the field to the view. Numeric fields may receive a default aggregation; inspect whether the pill shows SUM, AVG, or AGG.
Change view dimensions and filters and verify the formula still answers the intended question.
Create a simple calculated field · Calculation syntax and functions
Do not confuse row ratios with aggregate ratios
For order data with sales and profit, these calculations answer different questions:
**Average of row ratios:** AVG([Profit] / [Sales]) gives each row equal weight. Small and large orders may count equally.
**Ratio of totals:** SUM([Profit]) / SUM([Sales]) weights rows by their sales and describes the overall portfolio. Tableau’s basic example uses an aggregate ratio.
For illustration, order A has sales 10 and profit 5 (50%); order B has sales 90 and profit 9 (10%). The unweighted average of row ratios is 30%, while total profit 14 divided by total sales 100 is 14%. Which is right depends on the metric definition. Tableau may display a numeric field as SUM by default, so summing row ratios may be unintended.
Decide what a zero or null denominator means: zero, null, or excluded. Returning 0 to suppress a divide-by-zero error can affect averages and sums, so follow the metric definition.
Diagnose aggregation errors
The “Cannot mix aggregate and non-aggregate” error often means the formula mixes source-row fields and aggregated values. Check each term, confirm whether the question is at row, view, or separate LOD grain, and make the levels consistent. If comparing a row value to a differently scoped average, consider an appropriate LOD expression. For ranking, running totals, moving averages, or LOOKUP across the view, check table-calculation addressing and partitioning.
Tableau notes that repeatedly referencing a complex calculated field inside another calculation may repeat work. Reduce repeated nested references when sensible, then check performance in a representative workbook. Do not add complexity without a need. Calculation best practices
Validate before sharing
Compare a small cross-tab by order ID, region, and period with source rows.
Change the field aggregation (for example SUM versus AVG) and confirm the result changes as expected.
Test region and date filters, including the behavior of FIXED LOD versus ordinary filters.
Include boundary cases: zero, null, negative values, duplicate keys, date boundaries, and empty categories.
Before editing a shared field, use Sheets Affected to see which worksheets will change.
Record units and metric meaning. A correct number may need number or date formatting rather than another calculation.
Example: add a profit-ratio card
If the goal is overall profit ratio for the selected period, use the concept SUM(Profit) / SUM(Sales), place it in a view, and verify it is evaluated as an aggregate (often shown as AGG). Compare period totals with a separate check. If the intended metric is the average order-level ratio, define that separately and name it clearly. This is an illustrative workflow, not a claim that a test was run.
Sources
[Tableau Help: Get Started with Calculations](https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_create.htm)
[Tableau Help: Choosing the Right Calculation Type](https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_which.htm)
[Tableau Help: How LOD Expressions Work](https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_lod_overview.htm)
[Tableau Help: Writing Calculations](https://help.tableau.com/current/pro/desktop/en-us/functions_operators.htm)
[Tableau Help: Calculation Best Practices](https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_bestpractices.htm)
[Tableau Help: Calculated Field Tips](https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_tips.htm)