You can create calculated fields in your Tableau visualization. Calculated fields are fields that you create that don’t already exist in your data source. These calculated fields are created using formulas that are often based on other fields. You create calculated fields in Tableau using formulas. You can include the following elements in a formula:
Fields: These consist of the existing fields in your data source and can include other calculated fields and sets. In formulas, fields appear in orange text.
Functions: These are built-in operations that can be performed on data, such as COUNT, DATETIME, SUM, FIND, and DAY. Functions appear as light blue text in formulas.
Operators: These include the standard mathematical operators like +, –, and *. Operators show up as black text in formulas.
Parameters: These are placeholder variables that you can use in a formula so that the actual value is specified at runtime. Parameters appear as purple text in formulas.
Comments: You can add comments to your formulas to provide a level of documentation. Comments show up as green text in formulas. Items you enter after two forward slash marks are considered comments.
You can create quite complex calculated fields, but for this example, let’s have a look at creating something simple — a Profit Ratio field that’s the result of dividing the sum of the profit measure by the sum of the sales measure. Here’s what you need to do:
After you’ve connected to your data source in Tableau, open a worksheet.
You can use an existing worksheet or a new worksheet.
Click the down arrow to the right of the Dimensions header and choose Create Calculated Field from the pop-up menu that appears.
Enter a name for the calculated field in the text box at the top of the dialog box.
Be sure to use a descriptive name, because this is the name that will appear in the list of fields in the Data pane.
Add the fields that you want to use in the formula by dragging and dropping the field onto the dialog box. (Note that you can also start typing the field name and then select the field from the list that appears.) Add operators by typing them in directly.
In this case, drag the Profit field onto the dialog box, then type the sign for division and add Sales after it.
If you want to use any of the built-in functions in your formula, click the small arrow at the right side of the dialog box and then select the desired function from the list that appears.
In this case, because you are computing a profit ratio that requires a weighted average, you will want to be sure to sum our measures before you divide them. Highlight Profit in the calculated field dialog box, and then click the arrow on the right to bring up the function list.
Search for the aggregation of SUM and double-click. You’ll notice that the aggregation gets put around the field with open and end parentheses. Do the same for Sales.
Click OK to finish creating the calculated field.
When you click OK, Tableau adds it to the list of fields in the Data pane, and you can then use the calculated field in your views or in other calculations.
Tableau refers to the dialog box shown in this example as the Equation Editor. The name never appears in the dialog box, so you’ll be forgiven if you just think of it as the dialog box where you create formulas.
Sign up for insider news on books, authors, discounts and more content created just for you.