Calculated Field
Calculated Field
Calculated fields allow you to create new data from data that already exists
in your data source. When you create a calculated field, you are essentially
creating a new field (or column) in your data source, the values or members
of which are determined by a calculation that you control. This new
calculated field is saved to your data source in Tableau, and can be used to
create more robust visualizations. But don't worry: your original data
remains untouched.
You can use calculated fields for many, many reasons. Some examples might
include:
To segment data
To convert the data type of a field, such as converting a string to a
date.
To aggregate data
To filter results
To calculate ratios
Note: The example in this article uses the Sample-Superstore data source
that comes with Tableau Desktop. To follow along with the steps in this
article, connect to the Sample-Superstore saved data source and navigate
to Sheet 1.
3. Tip:To see a list of available functions, click the triangle icon on the
right-side of the Calculation Editor.
3. When finished, click OK.The new calculated field is added to Data pane
as a measure because it returns a number. An equal sign (=) appears
next to the data type icon. All calculated fields have equal signs (=)
next to them in the Data pane.
3. On the Rows shelf, click the plus icon (+) on the Category field to
drill-down to Subcategory.
1. From the Data pane, drag Discount Ratio to Color on the Marks
card.The view updates to highlight table.
o Binders are heavily discounted in the Central region. Notice that
Discount Ratio is automatically aggregated as a sum.
2. On the Rows shelf, right-click SUM(Discount Ratio) and
select Measure (Sum) > Average. The view updates to show the
average of discount ratio.
Edit a Calculated Field
If at any time you need to change a calculation, you can edit the calculated
field and it will update across your entire workbook.
1. In the Data pane, right-click the calculated field and select Edit.
For this example, the formula is changed to return a discount ratio for
orders over 2000 USD in sales:
3. Click OK.
The view updates to reflect the changes automatically. You do not need
to re-add the updated calculated field to the view.
See Also