Module 03 · Calculations

Your first calculated field

Build your own Profit field with a simple formula in the calculation editor.

Step by step8 minLesson 10 of 21 Free

A calculated field is a new field you build yourself with a formula, much like an Excel formula. The classic example: Profit = Revenue − Cost for every order. The formula lives only in the Tableau workbook; your Excel file stays unchanged. The editor is exactly the same in Tableau Public and Tableau Desktop.

Illustration of the Tableau calculation editor: the Analysis menu with the Create Calculated Field... command, a dialog named Profit holding the formula [Revenue] - [Cost] with the status The calculation is valid. and the Apply and OK buttons, and the Profit field with the =# icon in the Data pane. Zoom
The calculation editor: name at the top, formula in the middle, status at the bottom left.

Click a number on the picture or in this list to highlight that area.

Step by step

  1. Step 1: Open a new sheet (the New Worksheet icon in the tab strip at the bottom), then choose Analysis → Create Calculated Field... from the menu (number 1). A small calculation editor opens over the sheet.

    Tip: Another way: right-click the Revenue field in the Data pane → Create → Calculated Field.... You get the same editor, though the formula area may already contain [Revenue]; just complete it to [Revenue] - [Cost].

  2. Step 2: In the name box at the very top (number 2), change Calculation1 to Profit. Then type this formula in the formula area (number 3; the field name is not part of the formula; it only goes in the name box):

    Tableau
    [Revenue] - [Cost]

    Tip: As you type [Rev, Tableau suggests matching field names; press Enter to pick one. You can also drag fields from the Data pane into the formula area. The small triangle on the right edge of the editor opens the list of functions with explanations.

  3. Step 3: Check that the status at the bottom left (number 4) reads The calculation is valid., then click OK (Apply saves without closing the editor). The Profit field appears in the Data pane with the =# icon (number 5). Double-click Profit: Tableau puts SUM(Profit) on Rows and draws a single bar.

    Watch out: The formula [Revenue] - [Cost] is calculated per row (per order), then Tableau adds the results up. For ratios such as margin, don’t write [Profit] / [Revenue], because Tableau would add up the ratios of 1,089 rows. Write SUM([Profit]) / SUM([Revenue]) instead, then change its format to percentage.