Applying logical functions

Tableau provides various logical functions, such as CASE, IF, and IIF, to create calculated fields based on some conditions. In this recipe, we will create and see the use of some of these logical functions.

Getting ready

Let's use the sample file Sample – Coffee Chain (Access). Open a new worksheet and select Sample – Coffee Chain (Access) as the data source.

How to do it...

Once the data is loaded on the worksheet, perform the following steps to create calculated fields based on conditions:

  1. Right-click on Product Type from Dimensions and click on Create Calculated Field.
  2. In the Name box, enter Coffee or Tea.
  3. In the Formula box, enter the CASE [Product Type] WHEN 'Coffee' THEN 'Coffee' WHEN 'Espresso' THEN 'Coffee' WHEN 'Herbal ...

Get Tableau: Creating Interactive Data Visualizations now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.