Introduction to Tableau Calculated Field
Tableau date functions are highly useful inbuilt date functions, such as DAY, MONTH, YEAR, DATEDIFF, MAX, MIN, and, TODAY, etc. which are provided by Tableau software, and which enable the user to manipulate the data source, in the context of dates and times, as required, further allowing the user to perform various date operations on records, along with creation of complex date expressions, which facilitate in year to year, month to month or weekly analysis of data.
How does Tableau calculated field Works?
The calculated field will perform functions on values from other table fields or it will calculate values entered by the user. The calculated field will perform query operations during field value calculations. We can perform any calculation through calculated fields, and we can create N number of calculated fields. We need to create a calculated field, give the name to it and enter field value on which we want to perform calculations. If we take calculation field value from dimension, then the field is added to the measure or If we take calculation field from measure then the field is added to the dimension.
Examples of Tableau Calculated Field
Here are the following examples of Tableau Calculated Field mention below
We can create calculated fields by clicking on Analysis or clicking on the bottom arrow of the dimension field. We can create a calculated field from two choices.
- Go to the data source option, connect to the database file either present in the excel, text format or can connect to the live database or offline database.
- Open the calculated field and give the name to the calculated field and edit as per calculation you want to perform.
- We have pulled 100 sales record file, go to the sheet and rename it (as per your choice).
- We are going to calculate Min of the unit cost of the item from order date to ship date.
- MIN([Unit Cost]) – we have created a min named calculated field, and it is created at the measures field.
- Drag min calculated field to Text formatting option, hip date to columns and order date to rows.
- We can see min unit cost between order to ship date for items.
min unit cost for the 2010 year for the order to ship data is 6.9 and for 2011 (order date) to 2012 (ship date) is 525.0.
We are going to find Gain value for the item type as per each country.
- Create calculated field name it as Gain and add a calculation for
- Drag item type to columns and country to rows.
- Drag Gain (calculated field) to the Text formatting option.
- Drag Item type to filter option because there is multiple choice of item type, we are doing it for some 3-4 item type.
- Drag Gain (calculated field) to color formatting option, will get more visualized data.
- We can see in the above image different color is present for the item type with gain. For example – Fruits having orange color and Meat having a brown color. We can edit the default color filter (click on color->select edit color->choose the color you want).
- We can edit color, we have selected sunrise-sunset diverging color plate. Value changes as per the color changes in the visualization. Please refer to the below image for editing color.
We have pulled the sample superstore database; inner join is performed for people and order table sheet.
- We have created a calculated field for the AVG function. Average sales count for the person and the sub-category (fields from the two different databases).
- AVG([Sales]) – data inside the calculated1 field created.
- Drag person field to columns and sub-category to rows.
- Drag the calculated1 field to the color and text formatting option.
- Edit the color for the average range of sales, it will be easy to understand the result more effectively.
- For example – Average sales for a person name Anna andreadi with sub-category as art is 37. For machine average count is 1088 (the color is also changed).
- We can observe in the above image we have selected start, end and center value. We can edit the value as per our choice.
We have created a calculated field with discount measure, the calculated field has resulted in the dimension.
- we have created a calculated field for the ISNULL function, if the value dimension or measure field contains no values, the output of ISNULL is shown as True.
- If the value dimension or measure field contains values, the output of ISNULL is shown as False.
- Syntax – ISNULL([Discount])
- Drag ship mode to columns and region to rows.
- Drag Cal (calculated field created) to color.
- The result is shown as False because the discount field contains values, it is not empty.
We have learned tableau calculation fields, the reason to use calculated fields. Steps needed to create and edit calculated fields. When we are with calculations, fields are the best way to work with. We have multiple options available for the calculations like min, max, sum, ratio, etc.
Tableau is providing an error feature to validate the syntax we are using for the calculations. Measure and Dimension values are provided automatically for the calculation fields.
This is a guide to Tableau Calculated Field. Here we discuss how does Tableau calculated field Work along with the examples. You may also have a look at the following articles to learn more –