Friday, March 8, 2013

[TABLEAU] Understanding Logical Calculations



Understanding Logical Calculations

Logical calculations can be very useful in your analysis. Logical calculations can be very powerful in segmenting your analysis to particular members of a dimension or filtering out values from your data source. This article will provide a few basic examples of using IF statements with different types of logical operators. The logical operators used in Tableau include =, >, >=, <, <=, and <>.


Example 1: Group together two members of a field

In the following calculation, the East and South regions are combined by the “or” statement to create a new region called “East Coast” . The “or” statement will cause the results to appear when either of the conditions before the “or” statement are met. If you add this calculated field to a view, all of the values for these two members will be added together.  The calculated field is as follows:

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

In the following calculation, furniture sales for the Central region is calculated. Logical statements that use the “and” statement are useful when more than one field needs to be involved in the calculation. Only when both fields from the calculation are valid will the value appear. The calculated field is as follows:

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 compares to total sales.





Example 3: Exclude values

The calculation below uses the “not equal” (<>) operator. This type of operator is often used to exclude values or filter out a member of a dimension in a view. For example, the formula below calculates the total sales for all regions except East. The calculated field is as follows:
IF Region <> “East” then [Sales] End



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





Example 4: Create bins with variable bucket sizes

In the following calculation, the greater than or equal to (>=) operator can be used to create “bins” that values can be placed into. This type of calculation is very powerful and is also very similar to how KPI (Key Performance Indicators) are developed. The calculated field is as follows:

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:






                    



No comments:

Post a Comment