Understanding how to create and use Calculations

When working with data, we may come across situations where we may want to go beyond what is available from our data. There are times when the fields available in our data won't be enough to fulfill our requirements. For example, our data may have fields such as Selling price and Cost price. However, we may want to find out how much profit we made. Also, we may want to conditionally format our view to highlight losses. In these cases, it makes sense to create computed fields on the data fields and use them in our analysis.

On a broad level, we will classify our calculations into four categories as follows:

  • String Calculations
  • Arithmetic Calculations
  • Date Calculations
  • Logic Calculations

In order to create a calculated field, we can click on the dropdown or right-click on any Dimension or Measure and select the option of Create | Calculated Field…. Refer to the following screenshot:

Understanding how to create and use Calculations

Another option to create a calculated field is from the toolbar. Select Analysis | Create Calculated Field…. Refer to the following screenshot:

Understanding how to create and use Calculations

One more option to create a calculated field is by clicking on the dropdown from the Dimensions pane and then selecting the option of Create Calculated Field…. Refer to the following screenshot:

Understanding how to create and use Calculations

Once we select any of the previously mentioned options, we will get a new dialog box, as shown in the following screenshot:

Understanding how to create and use Calculations

The preceding screenshot shows the calculation dialog box. The top section is where we give a name to our calculation (ref. annotation 1). The next highlighted section (ref. annotation 2) is the data source that we are currently connected to. The type in box (ref. annotation 3), is the place where we will type our calculation or formulae. We can either drag and drop our fields from the Dimensions or Measures pane or simply start typing the field name and Tableau will auto suggest to help us pick up the relevant field. The next highlighted section (ref. annotation 4) is the list of various types of calculations such as number, string, date, logical, type conversion, and so on. Now, when we select the type of calculation as String from this list, then we will get the list of all the Functions classified as string functions in the list below, (ref. annotation 5). The highlighted section (ref. annotation 5), is basically the list of all the Functions that are available in Tableau. We will build our calculation logic using functions from this list. However, in order to use a particular function, we need to use it in the right syntax and that syntax is made readily available to us in the highlighted section labeled as (ref. annotation 6). When we select any particular Function, then we will get to see the syntax of that Function, an explanation as to what that Function does, along with an example in the highlighted section labeled as (ref. annotation 6). This is more of a quick help section to understand more about each function in terms of what it does, how to use it, and examples to give better clarity about using that function.

When we create a calculated field, then depending on the output, the calculated field will either be a Dimension or a Measure.

Also, any calculated field in Tableau will be shown with = as a prefix icon. This helps us quickly differentiate between the fields that are coming from our data and the fields that are computed in Tableau.

Having said that, when we connect to any data, by default we will see a field called Number of Records with = as a prefix icon. As mentioned in earlier chapters, this is a default pre-computed field that shows us the number of records that we are dealing with after we have connected to our data.

Now that we know how to create calculated fields in Tableau, let's get to actually creating different types of Calculations.

Tip

Please remember that all the calculations that we create in Tableau will stay in the Tableau workbook and will not be written back to your database. By default, Tableau Desktop is a read-only tool with no write back functionality.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.221.144