<retail:basket_affinity>

<retail.basket_affinity> expands upon <affinity> and supports the common specific retail use case of calculating basket affinity.

Description

<retail:basket_affinity> makes the more general <affinity> operation convenient and specific for retail use cases by performing some additional calculations after the operation, by giving attributes more retail-specific names, and by providing a TRS panel for the operation.

Syntax

<retail:basket_affinity
         basket_id="[TRANSACTION_ID_COLUMN]"
         prod_col1="[PRIMARY_PRODUCT_COLUMN]"
         prod_col2="[SECONDARY_PRODUCT_COLUMN]"
         prod_filter1="[PRIMARY_PRODUCT_VALUES]"
         prod_filter2="[SECONDARY_PRODUCT_VALUES]"
         copurchase_threshold=
         avgcol="[SALES_COLUMN]"
         ignoresegby="0|1"
         removediag="0|1"
         removebelowdiag="0|1">
</retail:basket_affinity>

Attributes

basket_id
The "basket", or transaction ID column. The table must be segby this column, unless you indicate ignoresegby="1". This attribute is required.
prod_col1
The primary product column for comparison. This attribute is required.
prod_col2
The secondary product column for comparison. This attribute is required.
prod_filter1
An optional filter for the primary product values in prod_col1.
prod_filter2
An optional filter for the secondary product values in prod_col2.
copurchase_threshold
The default value is "0.0".
avgcol
The sales column. This attribute is optional.
ignoresegby
Set to "1" to ignore the segmentation requirement. You may return nonsensical results if the data is not in fact segby. The default value is "0".

Example: Retail affinity analysis

The following example demonstrates how to perform affinity analysis on products of the group Snack-Chips/Pretzels. We set the prod_filter1 attribute to "1460" (for the chips/pretzel group). We limit the results so that there are a minimum of 100 transactions containing both items: the chips/pretzel item and the accompanying item ("coinc>=100"). Then we sort in descending order by average basket, so we can see which items when purchased with a chips and pretzels item resulted in the largest baskets.

<base table="retaildemo.retail.sales_detail"/>
<link table2="retaildemo.retail.products" col="sku" cols="group"/>
<retail:basket_affinity basket_id="transid" prod_col1="group" prod_col2="sku" prod_filter1="1460" 
    avgcol="xsales"/>
<sel value="coinc>=100"/>
<sort col="avgbskt" dir="down"/>
<link table2="retaildemo.retail.products" col="key1" col2="group" cols="groupdesc"/>
<link table2="retaildemo.retail.products" col="key2" col2="sku" cols="description"/>
<col name="groupdesc" fixed="1"/>
<col name="description" label="Description" fixed="1"/>