Comprehensive Tableau Reference Guide: Calculated Fields-Logical Functions

Comprehensive Tableau Reference Guide: Calculated Fields-Logical Functions
Comprehensive Tableau Reference Guide is a blog series for explaining the basics of Tableau Software. So, if you are a newbie planning to get started with Tableau or if you simply want to explore the popular features in Tableau, then these step-by-step guides are perfect for you. In this blog, we will discuss about Logical Functions in Tableau.

  • Go to the Calculated Field window:

1

  • Go to Functions table. From the drop-down menu, select the option ‘’Logical’’:

2

  • This selection filters the list of functions to display a listing of only logical functions, which consists of seven different functions:

3

We will explain these functions one by one.

  • CASE Function:

CASE expression WHEN value1 THEN return1 WHEN value2 THEN return2… ELSE default return END

The CASE function is applied when we need to perform a logical test. This function returns values based on the result of the logical test. A CASE function can also be written as an IF function. Generally, CASE function statements are simpler and shorter.

Example of a formula using CASE function:

004

Going through the country field, when the function comes across the value ‘’United States’’, it uses ‘’USA’’. On the other hand, when it comes across “United Kingdom’’, the function uses ‘’UK”. For all other values in the country field, ‘’World’’ is used.

  • IF Function:

IF test THEN value END/IF test THEN value ELSE else END

A logical test can be created using the IF function. The function works like this- IF the test is true THEN carry out the given condition. The test portion of the function must be Boolean. This can be achieved either by selecting a Boolean field from data source or by constructing the expression using operators and logical comparisons (AND, OR, NOT).

Example:

Logical205

IF test1 THEN value1 ELSEIF test2 THEN value2 ELSE else END

This statement is used when the functionality of IF function needs to be expanded. Additional IF-THEN statements can be incorporated through ELSEIF. Here’s an example to rewrite the CASE formula above with IF-THEN-ELSEIF statement:

Logical3-03

The result is the same as before.

  • IFNULL Function:

IFNULL(expression1, expression2)

The IFNULL function is used to perform a true/false test and check if the value in the tested field is NULL or not. If the value isn’t null then the first value of the function is used, and if the value is null then the second one is used.

Logical4_05

If Total Population of a country has no value, then it will be reset as zero and the null shall be eliminated from the newly created field.

  • IIF Function:

IIF(test, then, else, [unknown])

IIF function is very much alike the IF function described above, just a shorthand version for the IF-THEN-ELSE statement. The final argument of IIF function can define a value in case the test produces an unknown result. Like the IF function, the test must be Boolean, either by data type or the result of the test must give a Boolean value.

Here’s an example:

Logical5-06

If the % of change field is lower than 5% then the value Poor will be returned, or else the value Good will be returned.

  • ISDATE Function:

ISDATE(string)

The ISDATE function is used to determine if a string argument can be converted to a valid date (TRUE) or not (FALSE).

Example:

Logical6_1

This formula is supported by Tableau since the field used is a string data type, however each result will be FALSE. This function comes handy in case dates are formatted in a manner that is unrecognizable by a user, like ISO 8601.

Example:

Logical7_2

The above value stands for September 1, 2014 and is obviously a valid date.

  • ISNULL Function:

ISNULL(expression)

This is a simple function that checks if an expression is null (TRUE) or not (FALSE).

Example:

Logical8-03

The Filter card enables users to filter null values from their visualization.

  • ZN Function:

Statement: ZN(expression)

The ZN function is a variant of the ISNULL and IFNULL functions. It tests whether a function is null or not. In case the function is null, it returns a zero value.

Example:

Logical9_04

It is natural to feel overwhelmed when you see a list of logical functions for the first time. Since we have discussed each one of them, hopefully these functions will come handy in your visualization and data leveraging pursuits.

To learn more about Tableau functions, follow Dexlab Analytics– it is one of the best Tableau training institutes in Delhi. Do take a look at their Tableau BI training courses.

 

This article has been sourced from:  https://interworks.com/blog/ccapitula/2015/04/01/tableau-essentials-calculated-fields-logical-functions

 

Interested in a career in Data Analyst?

To learn more about Machine Learning Using Python and Spark – click here.

To learn more about Data Analyst with Advanced excel course – click here.
To learn more about Data Analyst with SAS Course – click here.
To learn more about Data Analyst with R Course – click here.
To learn more about Big Data Course – click here.

May 16, 2018 7:50 am Published by , , , , , ,

, , , , ,

Comments are closed here.

...

Call us to know more

×