Tableau

Calculated Field

Also called: Tableau calculation, Custom field, Calc field

A calculated field is a new field in Tableau defined by a formula over your existing fields, such as a profit ratio, a flag or a cleaned-up date, that you can use in views like any other field.

A calculated field named Profit Ratio, defined as SUM([Profit]) / SUM([Sales]), adds a column to a region table: APAC 15.0%, EMEA 20.0%, LATAM 10.0%, North America 20.0% and 18.0% overall on sales of 6.0 million dollars and profit of 1.08 million.

What a calculated field does

Your data has fields like Sales and Profit. A calculated field adds one that isn’t in the data, built from a formula. It lives in the workbook, not in the source, so the database stays untouched.

The example above is a Profit Ratio:

SUM([Profit]) / SUM([Sales])

It’s used like any other field: drag it into a view and Tableau calculates it for whatever the view is split by. With Region in the view it gives one ratio per region, and the overall ratio in the total.

Kinds of calculation

  • Row-level. Calculated once per record before anything is totalled, such as [Sales] - [Cost], or a text clean-up.
  • Aggregate. Calculated on totals, such as SUM([Profit]) / SUM([Sales]).
  • Logic. IF, CASE and similar, for flags and groupings, for example labelling orders “Large” or “Small”.
  • Table calculations. Calculated on the results already in the view, for running totals or ranks. This is a different family with its own rules.
  • Level of detail (LOD). Calculated at a level you choose, which has its own entry.

Ratio of sums, not average of ratios

Two ways to get an overall profit ratio: total profit 1.08M divided by total sales 6.0M gives the correct 18.0%, while averaging the four regional ratios gives 16.3%

The most common mistake is averaging ratios. Averaging the four regional ratios (15%, 20%, 10%, 20%) gives 16.3%, which treats LATAM’s $0.6M the same as North America’s $2.4M. Dividing the totals gives the true 18.0%. Aggregate the numerator and denominator first, then divide.

Calculated fields in Power BI vs. Tableau

TableauPower BI
LanguageTableau calculation syntaxDAX
Where you write itIn a worksheet’s Data paneIn the model, as a measure or column
Row-level vs. aggregateSet by whether you aggregate in the formulaA measure vs. a calculated column

Best practices

  • Name fields for what they mean. “Profit Ratio” beats “Calculation1”, and other authors can find it.
  • Aggregate before dividing. Ratios should be built from sums, as above.
  • Keep formulas short. If one needs lots of nesting, split it into two fields that each do one thing.
  • Handle blanks on purpose. Decide what a null should become, for example with ZN(), which turns nulls into zero, rather than letting it ripple through.
  • Check the total row. If the grand total doesn’t make sense, the formula’s level is wrong.

Mocking up calculated fields

Every number on a mockup should have a definition, and ratios are where definitions go wrong. Writing “Profit ÷ Sales, total over total” next to the KPI at the mockup stage settles it before anyone builds the field.

Related terms

Common questions

How do you create a calculated field in Tableau?
In Tableau Desktop, open the Analysis menu and choose Create Calculated Field, or right-click in the Data pane. Name the field, write the formula, and save it. It then appears in the Data pane and can be dragged into any view.
Is a Tableau calculated field the same as a Power BI measure?
They're similar but not identical. Tableau calculated fields are written in Tableau's own formula language and live in the workbook, while Power BI measures are written in DAX and live in the semantic model. The Measure vs. Calculated Column entry covers the Power BI side.
Why does Tableau say I can't mix aggregate and non-aggregate arguments?
A formula can't combine a total such as SUM([Sales]) with a raw row value such as [Profit] in the same expression. Aggregate both, as in SUM([Profit]) / SUM([Sales]), or neither.

Mock it up before you build it

Lay out your Power BI or Tableau dashboard in Mockko, get sign-off, then build. Free to start.

Try Mockko free