Lift a chestnut! Tableau Trise (114): Shopping Basket Analysis Market Basket Analysis
published: 2021-06-07 21:59

About shopping basket analysis:Shopping Basket Analysis Market Basket Analysis is the purchase of customers' purchase behavior. Multi-industry such as retail, telecommunications, financial services, insurance, medical care, can explore commercial interests and establish competitive advantages by understanding customer purchase habits and rules.

"Ada, how can I calculate a product purchase in Tableau, and buy a number of orders in other types of products?" Many users have proposed similar needs.

An important part of the shopping basket analysis is required to complete the relationship of the relationship (Co-Occurrence).

We can implement this calculation effect in Tableau. Look together!

The Tableau tricks that "lift a chestnut" in this issue, Ada wants to share the Tableau tricks that implement the shopping basket analysis Market Basket Analysis.

For easy learning, chestnuts use the sample of Tableau to bring the sample - supermarket data source.

Specific steps are as follows:

01, create parameters

First, connect an example - supermarket data source. Then, create 1 parameter, named "Select Product", the data type is selected to "String", the Allowed Value Select "List", "Value List" Select all values from the "Sub Category" field from the field.


After the creation is complete, this parameter control is displayed.

02, create a calculation field

We need to create 2 calculation fields:

❶ The first calculation field, named "At the same time," (the formula is as follows), used to identify the order (except for the user through parameter selection), other products included.

IF [Subcategory] <> [Select Product] THEN [Subcategory] END


❷ The second calculation field is named "Product Count" (the formula is as follows), which is used to count the matched product.

IF [subcategory] = [Select Product] THEN 1 End


03, create a set

Next, we create a set to determine if a certain order has the item selected in the parameter control: The "Order ID" field in the right miles, select "Create" - "Set".


Then, in the pop-up creation set dialog box, the name "Do you contain the selected product", go to the Condition tab, select "Press" - "Product Count" - "-"> = " -"1".

This set is used to determine if a certain order has an item selected in the parameter control.


04, create a view

Finally, let's create a view you need:

Drag "also purchased" to the "line" function area;

Drag the "Order ID" to the Column function area, in the Warning dialog box, click Add All Members;

On the Column, click the Order ID field and select "Measure" - "count (not repeated)" to change the aggregation;

Right-click the "Null" strip in the graph and select "Exclude";

Drag the "Whether to include the selected product" set to the Filter Signature.

In this way, we can calculate: At the same time, purchase the amount of orders that contain multiple subcategories products.


Through the right screen, we choose different product categories, easy to view the order quantity of other commodities that "buy at the same time" at the same time.

Tableau skills, have you get? Try it quickly!