KNOWLEDGE BASE

Understanding Logical Calculations


Product(s): Tableau Desktop
Version(s): 8.1, 8.0, 7.0
Last Modified Date: 16 Aug 2016

Logical calculations can be useful when you want to create specific views from a data source without changing the source itself. For example, combine different members of a dimension or filter a segment of the data out of a view. This article provides a few basic examples, using the IF statement with different types of logical operator.

Logical operators used in Tableau include AND, OR, =, >, >=, <, <=, and <>, and others. For more information, refer to Operators in the Tableau Desktop Online Help.

Example 1: Group members of a field

In an OR statement only one of the conditions in the statement needs to be true for the entire calculation to evaluate to true. In this example, an OR operator is used to create a new region called East Coast, made up of members of the East and South regions.

IF [Region] = “East” OR [Region] = “South” THEN “East Coast” ELSE [Region] END

Using this calculation, you can create a view like this:

Example 2: Compare Values

Logical statements that use the AND operator are useful when more than one field needs to be involved in the calculation. In an AND statement, all conditions must evaluate to true for the overall calculation to be true. The following calculation finds furniture sales for the Central region:

IF [Region] = “Central” AND [Product Category] = “Furniture” THEN [Sales] END

Using this calculation in a view easily shows how furniture sales in the Central region compare to total sales.

Example 3: Exclude Values

The calculation in this example uses the NOT EQUAL (<>) operator. This operator is often used to exclude values or filter a member of a dimension out of a view. The following formula calculates the total sales for all regions except East:

IF Region <> “East” THEN [Sales] END

Using this calculation, you can create a view like this:

Example 4: Create Virtual Bins

The Greater Than or Equal To (>=) operator can be used to create virtual bins to categorize data in different ways. This type of calculation is very useful and is similar to how KPIs (Key Performance Indicators) are evaluated. In this calculation, the >= operator is used to group sales into large, medium, and small orders based on the dollar amount.

IF [Sales] >= 5000 THEN “Large Order”
ELSEIF [Sales] >= 1000 THEN “Medium Order”
ELSE “Small Order” END

Using this calculation, you can create a view like this:

 

Alternate Search Terms:operators, logical statements, calculation,
Did this article resolve the issue?