Applying the If-Then logic

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.

Getting ready

Let's use the sample file Sample – Superstore Sales (Excel). Open a new worksheet and select Sample – Superstore Sales (Excel) as the data source.

How to do it...

Once the data is loaded on the worksheet, perform the following steps to create a new calculated field:

  1. To categorize shipping modes into air and ground, right-click anywhere on the Dimensions pane and select Create Calculated Field.
  2. In the Name box, enter Ship Type.
  3. In the Formula box, enter IF [Ship Mode] = 'Delivery Truck' then 'Ground' Else 'Air' End and hit OK.

How it works...

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset