Toan Hoang

TAB106 / Calculated Fields

Calculated Fields are additional fields that are a combination of formulas and existing fields in your data source. When you create a calculated field, you are essentially creating a new data field that can be used in your data visualisations.

There are three main types of Calculated Fields:

For the remainder of this article, we will go through Basic Calculations.

Note: We can only introduce you to Basic Calculations, but you will need to practice and get used to the common Calculations as well as build an awareness of what Calculations are at your disposal.

Calculated Fields

Let us get started straight away by creating a Calculated Field, you have a few options on how to do this:

  1. In a worksheet and Menu Bar, go to Analysis and select Create Calculated Field.
  2. Right-click in an empty space in the Data Pane and select Create Calculated Fields.
  3. Right-click on a Field in the Data Pane, go to Create and select Calculated Field.
  4. In the Data Pane, on the right of the Dimension header, click on the Down Arrow (Down Carrot), and select Create Calculated Field.
  5. You can type formulas directly in the Columns, Rows and Marks and then drag the result onto the Data Pane..

As you can see there are several different ways of creating a new Calculated Field depending on what is quickest at this moment. Please have a try and create Calculated Fields using all 5 methods.

Note: If you know of an additional way of creating Calculated Fields, please do let me know. I am sure there are other ways too.

Calculation Editor

Once you go through one of above you will be presented with following:

Let us have a look at what we have:

  1. Is where you put the name of your Calculated Field, this must be unique.
  2. This is where you will write your Calculated Field formula. This includes auto-complete as well as auto-formular-validation.
  3. This is a logical grouping of available Calculations. We will go through the formulas based on these groupings. You can also search to see if your formula you require exists.
  4. Here is the list of fomulas that you have available to you at present.
  5. If you click on a function listed in 4, you will see a short description.

All of this is available to you to use in your work. So let us go through what is available to us.

Note: There is current no real way of defining corporate custom functions, this is a pet peeve, but I hope this will be a feature in the future.

LITERALS, OPERATORS AND SYNTAX

Your Calculations will be made up of a Formula that returns a value; your formula must be valid and can comprise of Data Fields, Calculated Fields, Operators and Functions. We are going to look through the list of functions available, but first:

LITERALS

OPERATORS

OPERATOR PRECEDENCE

Ideally you should always use parenthesis to make your formulars clear, but here is the Tableau Operator Precedence.

PRECEDENCEOPERATOR
1– (Negate)
2^ (Power)
3*
/
%
4+
5==
>
<
>=
<=
!=
6NOT
7AND
8OR

NUMBER FUNCTIONS

Take a moment and experiment with the various number functions. I personally use SIN(), COS() and RADIANS() frequently for drawing. ZN() is also fantastic for dealing with null values. MIN() and MAX() and others on the list are commonplace in Tableau.

STRING FUNCTIONS

Have a look at these functions and try them out. I personally use SPLIT(), LEN(), TRIM() and surprisingly CHAR() very often. Explore and Experiment.

DATE FUNCTIONS

Before we go into dates, let us first look at a table of date parts.

DATE_PARTVALUES
‘year’Four-digit year
‘quarter’1-4
‘month’1-12 or “January”, “February” etc
‘dayofyear’Day of the year
‘day’1-31
‘weekday’1-7 or “Sunday”, “Monday” etc
‘week’1-52
‘hour’0-23
‘minute’0-59
‘second’0-60
‘iso-year’Four-digit ISO 8601 year
‘iso-quarter’1-4
‘iso-week’1-52, start of the week is always Monday
‘iso-weekday’1-7, start of the week is always Monday

Now let us look at the functions available to us.

I do not think there is a single function I do not use with regularity. One of the key things and reference points is the date parts in the section above.

CONVERSTION FUNCTIONS

You really need to know all of the above and changing data types in formulas is a must.

LOGICAL FUNCTIONS

This is also essential viewing and something that you must have a play with and understand.

AGGREGATE FUNCTIONS

Aggregating data is key to generating concise and performant dashboards, so , it is crucial that you spend time understanding what is available to you. Experiment with the functions above, and do a Google search on some functions that you are not sure about, you will find of information about there.

USER FUNCTIONS

These are really useful and I use them often to provide additional auditing information in a dashboard, or for row level security or use based filtering.

This is not a full list but hopefully will highlight the vast majority of basic functions that are available to you. For a full, comprehensive and managed list, please visit the Tableau Official Documentation at https://onlinehelp.tableau.com/current/pro/desktop/en-us/functions.htm

Summary

In this part of our introductory series, we explored the Basic Calculations and the various available options. I would suggest connecting to your data source and having a play around with the different formulas to get used to the syntax as well as what is available.

I hope you enjoyed this tutorial, and look forward to the next one. I am always looking for ways to help share knowledge around the community, so if you want to know more about something, and wish there was a tutorial out there, do get in touch on Twitter at @Tableau_Magic.

Exit mobile version