0% found this document useful (0 votes)
20 views

Calculated Field

Calculated field

Uploaded by

maryfathimaanuja
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Calculated Field

Calculated field

Uploaded by

maryfathimaanuja
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Why Use Calculated Fields

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

Create a calculated field


Once you have determined the type of calculation you want to use, it's time
to create a calculated field. This example uses a basic calculation.

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.

1. In Tableau, select Analysis > Create Calculated Field.

2. In the Calculation Editor that opens, do the following:


o Enter a name for the calculated field. In this example, the field is
called, Discount Ratio.
o Enter a formula. This example uses the following formula:

IIF([Sales] !=0, [Discount]/[Sales],0)


This formula checks if sales is not equal to zero. If true, it returns
the discount ratio (Discount/Sales); if false, it returns zero.

3. Tip:To see a list of available functions, click the triangle icon on the
right-side of the Calculation Editor.

Each function includes syntax, a description, and an example for your


reference. Double-click a function in the list to add it to the formula.
For more tips, see Tips for Working with Calculated Fields in Tableau.

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.

Use a calculated field in the view


Step 1: Build the view

1. From the Data pane, drag Region to the Columns shelf.

2. From the Data pane, drag Category to the Rows shelf.

3. On the Rows shelf, click the plus icon (+) on the Category field to
drill-down to Subcategory.

Step 2: Add the calculated field to the view

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.

To edit a calculated field:

1. In the Data pane, right-click the calculated field and select Edit.

2. In the Calculation Editor that opens, you can do the following:


o Edit the name of the calculated field.
o Update the formula.

For this example, the formula is changed to return a discount ratio for
orders over 2000 USD in sales:

IIF([Sales] > 2000, [Discount]/[Sales],0)

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

You might also like