Generate related lists of products that have similar attributes

camspy

New Member
Joined
Jan 7, 2022
Messages
43
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
We have a list of products in column A.
Each product has its set of attributes in column B.

The task is to generate a product with its 6 related products (in column C), which have similar attributes to that product, sorted by similarity.

Similar attributes mean that the products share a similar set of attributes. The more matching attributes, the more similar the product is.

Then, the most similar product goes to the top of the list, and the least similar product goes to the bottom.

The result should exclude the product for which we generated the list.

I provide sample data below.
In C2, I have put an example of what the result should look like.

sort.xlsx
ABC
1ProductAtributesResult: 6 related products
2Applepackaging,quantity,reliability,size,design,material,id,contentPear,Orange,Lemon,Fig,Lime,Lychee
3Apricotmake,content,brand,purpose,feel,color,id,photos,weight,packaging
4Avocadoreliability,size,design,taste,smell,feel
5Bananaquantity,design,safety,brand,smell,id,feel,photos
6Duriansize,color,content,feel,smell,quantity,brand,price,reliability
7Figpackaging,safety,weight,id,videos,photos
8Grapefruitweight,purpose,photos,packaging,material,make,color,content,videos,taste
9Grapesquantity,reliability,size,make,material,purpose,content,price
10Lemonpackaging,reliability,design,weight,smell,photos
11Limepackaging,quantity,weight,make,taste,material,price,feel
12Lycheeweight,content,taste,reliability,design,material,size,price,purpose,feel
13Mangotaste,material,purpose,feel,videos,photos
14Nectarinereliability,size,safety,make,material,content,color,photos
15Orangepackaging,quantity,reliability,make,purpose,smell,videos,photos
16Papayasize,design,weight,purpose,id,content
17Peachdesign,safety,content,price,feel,photos,price
18Pearpackaging,design,safety,taste,purpose,price
19Pineapplesafety,taste,content,price,feel,photos
20Plumreliability,size,make,material,content,color,price,photos
21Watermelonpackaging,quantity,safety,brand,make,taste,material,content
Sheet1



Thanks in advance.
 
As i am not clear please give example of expected result.
Here it is.
So, imagine, that without the negatives in the 1st row, Pear would have been added to the results column.
But since Pear is in the negatives list, it wasn't added. Instead, the next appropriate related product was added (Durian).

Book1
ABCD
1ProductAtributesNegativesResult: 6 related products
2Applepackaging,quantity,reliability,size,design,material,id,contentPear,BananaOrange,Lemon,Fig,Lime,Lychee,Durian
3Apricotmake,content,brand,purpose,feel,color,id,photos,weight,packaging
4Avocadoreliability,size,design,taste,smell,feel
5Bananaquantity,design,safety,brand,smell,id,feel,photos
6Duriansize,color,content,feel,smell,quantity,brand,price,reliability
7Figpackaging,safety,weight,id,videos,photos
8Grapefruitweight,purpose,photos,packaging,material,make,color,content,videos,taste
9Grapesquantity,reliability,size,make,material,purpose,content,price
10Lemonpackaging,reliability,design,weight,smell,photos
11Limepackaging,quantity,weight,make,taste,material,price,feel
12Lycheeweight,content,taste,reliability,design,material,size,price,purpose,feel
13Mangotaste,material,purpose,feel,videos,photos
14Nectarinereliability,size,safety,make,material,content,color,photos
15Orangepackaging,quantity,reliability,make,purpose,smell,videos,photos
16Papayasize,design,weight,purpose,id,content
17Peachdesign,safety,content,price,feel,photos,price
18Pearpackaging,design,safety,taste,purpose,price
19Pineapplesafety,taste,content,price,feel,photos
20Plumreliability,size,make,material,content,color,price,photos
21Watermelonpackaging,quantity,safety,brand,make,taste,material,content
Sheet1
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
What do you mean by negative list. Where it is located.
It's located in the col C.
I will get them added to column C, some rows can have 1 negative, some can have multiple ones comma delimited, and some can have no negatives.
Negatives are simply exclusions - the items that shouldn't be added to the final list of related products. But at the same time, there should still be 6 related products.
Here's some image that could help you understand how the Exclusion list (negatives) could look like:

1666088750140.png
 
Upvote 0
Try this code

VBA Code:
Function GetRelatedProductsLessNegative(RngPrd As Range, AtriRng As Range, CriPrd As String, CriAtb As String, NegCri As String)
Dim M, N, temp
Dim Ta As Long, T As Long, K As Long, Cnt As Long, X As Long
M = Split(CriAtb, ",")

Cnt = AtriRng.Cells.Count
ReDim Tly(1 To Cnt) As Long
With CreateObject("scripting.dictionary")

For Ta = 1 To Cnt
For T = 0 To UBound(M)
Tly(Ta) = Tly(Ta) + Evaluate("1*ISnumber(FIND(""" & M(T) & """," & AtriRng.Cells(Ta, 1).Address & "))")
Next T
.Add Tly(Ta) * 1000 - Ta, RngPrd.Cells(Ta, 1)
Next Ta

For Ta = 1 To Cnt
K = Application.Large(.keys, Ta)
If K > 0 And LCase(.Item(K)) <> LCase(CriPrd) Then
If InStr(1, LCase(NegCri), LCase(.Item(K))) > 0 Then GoTo Line1
temp = temp & "," & .Item(K)
X = X + 1
If X > 6 Then Exit For
End If
Line1:
Next Ta
End With
If temp = "" Then GetRelatedProducts = "" Else GetRelatedProductsLessNegative = Mid(temp, 2)
End Function

In D2 then copied down.
Excel Formula:
=GetRelatedProductsLessNegative($A$2:$A$21,$B$2:$B$21,A2,B2,C2)

ProductAtributesNegativesResult: 6 related products
Applepackaging,quantity,reliability,size,design,material,id,contentDurian,orangeGrapes,Lychee,Grapefruit,Nectarine,Papaya,Plum,Watermelon
Apricotmake,content,brand,purpose,feel,color,id,photos,weight,packagingGrapefruit,Orange,Banana,Durian,Fig,Lime,Lychee
Avocadoreliability,size,design,taste,smell,feelLychee,Durian,Apple,Banana,Lemon,Grapes,Lime
Bananaquantity,design,safety,brand,smell,id,feel,photosApricot,AppleDurian,Orange,Peach,Avocado,Fig,Lemon,Mango
Duriansize,color,content,feel,smell,quantity,brand,price,reliabilityGrapes,Lychee,Plum,Apple,Apricot,Avocado,Banana
Figpackaging,safety,weight,id,videos,photosGrapefruit,Apricot,Orange,Banana,Lemon,Mango,Apple
Grapefruitweight,purpose,photos,packaging,material,make,color,content,videos,tasteApricot,Lime,Lychee,Mango,Nectarine,Orange,Plum
Grapesquantity,reliability,size,make,material,purpose,content,priceLychee,Plum,Apple,Durian,Nectarine,Grapefruit,Lime
Lemonpackaging,reliability,design,weight,smell,photosBananaOrange,Apple,Apricot,Avocado,Fig,Grapefruit,Lychee
Limepackaging,quantity,weight,make,taste,material,price,feelGrapefruit,Lychee,Watermelon,Apricot,Grapes,Apple,Durian
Lycheeweight,content,taste,reliability,design,material,size,price,purpose,feelGrapes,Apple,Avocado,Durian,Grapefruit,Lime,Papaya
Mangotaste,material,purpose,feel,videos,photosGrapefruit,Lychee,Apricot,Lime,Orange,Pineapple,Avocado
Nectarinereliability,size,safety,make,material,content,color,photosPlum,Grapefruit,Grapes,Apple,Apricot,Durian,Lychee
Orangepackaging,quantity,reliability,make,purpose,smell,videos,photosGrapefruit,Apricot,Grapes,Lemon,Apple,Banana,Durian
Papayasize,design,weight,purpose,id,contentLychee,Apple,Apricot,Grapefruit,Grapes,Avocado,Banana
Peachdesign,safety,content,price,feel,photos,pricePineapple,Lychee,Banana,Durian,Pear,Plum,Apricot
Pearpackaging,design,safety,taste,purpose,priceLychee,Grapefruit,Lime,Peach,Pineapple,Watermelon,Apple
Pineapplesafety,taste,content,price,feel,photosPeach,Lychee,Apricot,Banana,Durian,Grapefruit,Lime
Plumreliability,size,make,material,content,color,price,photosNectarine,Grapes,Durian,Grapefruit,Lychee,Apple,Apricot
Watermelonpackaging,quantity,safety,brand,make,taste,material,contentGrapefruit,Lime,Apple,Apricot,Grapes,NectarineBanana,Durian,Lychee,Orange,Pear,Pineapple,Plum
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top