How to Create a Co-Occurrence Visualization In Tableau Using Parameters and Sets

You can create co-occurrence visualizations in Tableau. One practical application of such analysis is a market basket analysis, which can be used to discover and understand customer purchasing behavior. You can use the market basket analysis to answer questions like the following:
  • How many people bought both Product A and Product B?
  • What other products do people who purchased Product A generally buy?
  • Which other courses do students who enrolled in Course A frequently enroll in?
Follow the steps in this article to create a co-occurrence visualization (in this case, a market basket analysis view) using a parameter, calculated fields, and a set.
Step 1: Create a parameter that you will use to dynamically modify the view based on the item you select.
Step 2: Create calculated fields that you will use to return which items are also ordered when a particular item is ordered.
Step 3: Create a set to determine whether an order has the item that was selected in the parameter control.
Step 4: Build the view to display which items are also contained in an order with the selected item.

Step 1: Create a Parameter

  1. Open Tableau Desktop, connect to Microsoft Excel, and then open the Sample – Superstore data source.
  2. Drag the Orders sheet to the join area, and then click the sheet tab.
  3. Right-click in the Data pane, and then select Create Parameter.
  4. In the Create Parameter dialog box, do the following:
    1. Name the parameter. For this example, name the parameter Order Contains…
    2. For Data Type, select String.
    3. For Allowable Values, select List.
    4. In the List of values section, click Clear All, and then click Add from Field > Sub-Category.
    5. Click OK.
  5. Right click the Order Contains... parameter, and then select Show Parameter Control.

Step 2: Create Calculated Fields

  1. Select Analysis > Create Calculated Field.
  2. In the text box, enter Then Order Also Contains….
  3. Under the text box, enter the following:
    IF [Product Sub-Category] <> [Order Contains...] THEN [Product Sub-Category] END
  4. Verify that the calculation is valid, and then click OK.
  5. Create another calculated field by selecting Analysis > Create Calculated Field.
  6. In the text box, enter Product Matches.
  7. Under text box, enter the following:
    IF [Sub-Category] = [Order Contains...] THEN 1 END
  8. Verify that the calculation is valid, and then click OK.

Step 3: Create a Set

  1. Click the Order ID dimension down arrow in the Data pane, and then select Create > Set.
  2. In the Name text box, enter Order Has Selected Product.
  3. On the Condition tab, select By field, and in the drop-down lists, make the following selections and entries to build the condition:
    1. In the first drop-down list, select Product Matches.
    2. In the second drop-down list, select Sum.
    3. In the next drop-down list, select >=.
    4. In the last text box, enter 1.
    5. Click OK.

Step 4: Build the View

  1. Drag Then Order Also Contains to the Columns shelf.
  2. Drag Order ID to the Rows shelf. If a Warning dialog box appears, click Add all members.
  3. On Rows, click the Order ID down arrow, and then select Measure > Count (Distinct).
  4. Right-click the Null value on the x-axis, and then select Hide.
  5. Drag the Order Has Selected Product set to the Filters shelf.
  6. Click the swap button on the toolbar.
You can now use the Order Contains… parameter control to select an item in an order, and then view which other items are also contained in orders with the selected item.