1

Ive been working on VBA at work for almost a year and have managed to pull of some rather impressive things, normally I can find anything I'm not sure about with a series of searches on this site or others but this time I have come up blank, I guess its most likely because I don't really know how to frame the search properly :(

I'm looking to create a macro that analyses a customers sales history, then preforms a 'you might also like' search from our bestsellers list and returns the closest match to their bestseller. The product is books and due to many decades of bibliographic attention to detail within the industry each product can have up to 20 categories and I want to use this to find the closet match.

The info I have (the important bits)

    Sheet 1 - product id - customer sales quantity 
                     Product id 2 -customer sales quantity
                     Product id 3 -customer sales quantity
                     Etc etc ( usually up to 100)

Sheet 2 - product id - total company sales quantity
                 product id2 - total company sales quantity                                                     product id3 - total company sales quantity
                 Etc etc (Currently over 34000 and growing...)

Sheet 3 -     cat1 cat2 cat3 cat4 cat5 cat6 etc (to cat400) 
  Product id    1       0      1      1      0       0     
Product id2    0       1      1       0     1       0  
Product id3     1      0      1      1      0       0 

What I want to be able to is to find the bestseller from the customers list, look up all of the matching categories for that product on the cat reference table, find all results with an exact match to those categories and list them by total company's sales value. Although it is very possible that with the amount of possible categories there will not be an exact mach so I would like then to get the closest match of that product.....

Does that make sense? Please let me know if any more info is needed to help - even just a pointer towards some kind of function or a snippet of code that will help me on my way would be appreciated, I just have no idea how to find a match for an entire rows values.... and even less of an idea of how to find a closest match if there are no exacts...

Duke Rogers
  • 31
  • 1
  • 6
  • for this kind of search you shouldn't try to use the Item as a key (and look it up on a database). You should use **attributes** like `[year-range]` or Decade,`[Genre]` ar Sub-Types,`[Similar_Authors]` grouped on hard-coded lists, `[etc]` and than do the search on these attributes. Based on the result of you query, you should select the similar items in descending order by the no. of matching atrb.. More attributes > deeper search > a more accurate result. Basically Don't use 1/0 values but use IDs for attributes. If needed I can write down an example. – Takedasama Nov 29 '13 at 08:58

1 Answers1

2

Interesting question. There's no match function to achieve what you want. Instead, you need to first figure out what kind of algorithm/logic you want to use in order to determine the closest books. This will require a lot of weighing. Here's how I'd do it (without VBA):

Let's use the following data as example:

enter image description here

Approach:

  1. Combine product info with overall sales info, to have a weight for each book: enter image description here
  2. Determine to the "average preference" of the customers basket in sheet1. In order to do so:
    • Add the category information for the 400 categories to each product in the basket: enter image description here
      1. Sum each category for all basket products (see row 6 above)
      2. Determine the weigh (see row 7).
  3. Apply this preference to all products to determine the overall fit:
    1. Compare each product's categories with the preference: enter image description here
    2. Check that the product is not already in the basket: enter image description here
    3. Combine all three factor to determine each product's fit (by multiplying the factors) - and rank them using the RANK function: enter image description here
  4. Last but not least, retrieve the top X highest matches with a lookup: enter image description here

Here's the sample file.

Peter Albert
  • 16,917
  • 5
  • 64
  • 88