All IT Courses 50% Off
Tableau Tutorials

Co-Occurrence Visualization in Tableau

You can create co-occurrence visualizations also in Tableau. With a co-occurrence visualization, users can also pick one field value and then see which other fields’ values co-occur with and how often.

At a high level, the steps include:

  1. Create a parameter that is used to modify the view based on the item you select dynamically.
  2. Create calculated fields used to return which items are also ordered when a specific item is ordered.
  3. Create a set to decide whether an order has the item that was selected in the parameter control.
  4. Build the view for displaying which items are also contained in an order with the selected item.

The scenario uses the data source Sample – Superstore provided with Tableau Desktop.

Create a Parameter:

Follow the below-given steps to create a parameter and then display a parameter control that users can use to pick a Sub-Category value.

Step 1: Connect to the Sample – Superstore data source.

Step 2: Right-click in the Data pane and select Create > Parameter.

Step 3: In the Create Parameter dialog box, perform the following:

  1. Name the parameter as “Order Contains.”
  2. For the Data Type, select String.
  3. For Allowable Values, choose List.
  4. In the List of values section, select Add from Field > Sub-Category.
  5. Click OK.

Step 4: Right-click on the Order Contains parameter in the Data pane and select Show Parameter Control.

How to create Calculated Fields:

Follow the below steps to create the calculated fields that you will use to show which items are also ordered when the user’s item (via the parameter control) is ordered.

Step 1: Create a calculated field to identify products that the order also contains (in addition to the user selects).

Select Analysis > Create Calculated Field to open the calculation editor. Name the calculated field as Then Order Also Contains and type or paste the following:

IF [Sub-Category] <> [Order Contains] THEN [Sub-Category] END

You may need to replace &lt;&gt; with <> after you paste.

Step 2: Create another calculated field for identifying matching products.

Name the field as Product Matches and type or paste the following:

IF [Sub-Category] = [Order Contains] THEN 1 END

Create a Set:

Step 1: Now, create a set to determine whether an order has the item selected in the parameter control.

Step 2: Hover the cursor over the dimension Order ID in the Data pane, click on the down arrow present at the right end of the field, and select Create > Set.

https://help.tableau.com/current/pro/desktop/en-us/Img/cooccurrence_create_set.png

Step 3: In the Create Set dialog box, type Order Has Selected Product in the Name text box.

Step 4: Go to the Condition tab, select By field, and in the drop-down lists, perform the following selections and entries to create the condition:

  1. In the first drop-down list, select the option 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, type 1.
  5. Click OK.

Step 5: Click, OK.

How to build the View:

Finally, build the view for displaying which items are also contained in an order with the selected item.

Step 1: Drag Then Order Also Contains to Columns.

Step 2: Drag Order ID to Rows.

In the dialog box warning, click Add all members.

Step 3: Click the Order ID field on Rows and choose Measure > Count (Distinct) to change the aggregation.

Step 4: Right-click the Null bar on the x-axis and choose Exclude.

Step 5: Drag the Order Has Selected Product set to the Filters shelf.

Step 6: Press Ctrl+W to swap the fields between Rows and Columns.

You can now use the Order Contains parameter control for selecting an item in an order. Then you can see a bar chart showing which other items are also included in orders with the selected item.

https://help.tableau.com/current/pro/desktop/en-us/Img/cooccurrence_result.png

Benford’s Law:

Benford’s Law is a mathematical law stating that the leading or left-most digit in many real-life data sources is distributed in a particular manner. Specifically, number 1 occurs as the leading digit about 30% of the time, and as the numbers get larger, they occur less frequently, and with the number 9 occurring less than 5% of the time. When fraudsters are making data, they may not know to create fake data that conform to Benford’s law, and in some cases, it becomes possible to detect fake data or at least to create doubt about its veracity.

The process requires you to perform the following:

  1. Create calculated fields to use in the view.
  2. Set up the view.

How to create calculated fields to use in your view:

Step 1: In the Analysis menu, select Create Calculated Field for opening the calculation editor. Name the calculation as Leftmost Integer and type or paste the following:

LEFT(STR([Sales]),1)

Step 2: Create a second calculated field and name it Benfords Law. Type or paste the following:

LOG(INT([Leftmost Integer])+1)-LOG(INT([Leftmost Integer]))

How to set up the view:

Step 1: From the Data pane, drag Leftmost Integer to Columns, and then drag Orders(Count) to Rows.

Step 2: Click CNT(Orders) on Rows and select Quick Table Calculation > Percent of Total.

Your view will now show the distribution of first digits, and the size of the bars (decreasing from left to right) will suggest that the data, in this case, conform to Benford’s law.

Step 3: Drag Benfords Law from the Data pane to Detail on the Marks card. Click on Benfords Law on the Marks card and select Measure > Minimum.

Step 4: Switch from the Data pane to the Analytics pane and drag Distribution Band into the view. Drop it on cells.

https://help.tableau.com/current/pro/desktop/en-us/Img/benford1.png

Step 5: In the Edit Reference Line, Band, or Box dialog box, perform the following:

  1. Click on the Value field to view an additional set of options:
https://help.tableau.com/current/pro/desktop/en-us/Img/benford2.png
  1. In the Percentage area, type 80,100,120.

This will specify that you want bands spanning from 80 to 100 percent and from 100 to 120 percent. Next, you will also specify what value the percentages are referencing.

  1. In the Percent of field, choose MIN(Benford’s Law).

The Value field should now read at least 80%,100%,120% of Average Min. Benford’s Law.

The remaining steps will now configure the appearance of the reference bands.

  1. Set Label to None.
  2. Set Line to the thinnest available line.
  3. Select Fill Below.
  4. Fill the form and select Stoplight.
  5. Click on OK to exit the Edit Reference Line, Band, or Box dialog box.

Step 6: Click the toolbar button to display mark labels:

https://help.tableau.com/current/pro/desktop/en-us/Img/marklabels.png

The finished view should look like this:

https://help.tableau.com/current/pro/desktop/en-us/Img/benford3.png
Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button
Close
Close