At times, it becomes necessary to report values in a certain way; for example, displaying blank values as dashes or categorizing some values into buckets. Since these modifications are based on logic, they are created using logical functions.
Let's use the sample file Sample – Superstore Sales (Excel)
. Open a new worksheet and select Sample – Superstore Sales (Excel) as the data source.
Once the data is loaded on the worksheet, perform the following steps to create a new calculated field:
Ship Type
.IF [Ship Mode] = 'Delivery Truck' then 'Ground' Else 'Air' End
and hit OK.Tableau provides seven logical functions to test logical conditions and return some values depending on the result of the condition. In the previous recipe, we checked whether the Ship Mode
attribute was Delivery Truck
, and if it were, we returned the Ground
value as Ship Type
. Since we know there are only three types of the Ship Mode
attribute (Delivery Truck
, Express Air
, and Regular Air
), we don't need to check for other shipping modes as they both are of the Air
type.