It still only shows me the same output as shown. It shows products bought yesterday with the max order number (i.e. the very last order placed yesterday for every SKU(productCode)) It seems to be ignoring CustCode. Maybe If I try and explain more clearly you will be able to help So What I am trying to achieve is predict when someone is likely to run out of a particular product ProdRunDateKey CustCode OrderNumber ProdCode LongDescription 20140717 540150 3164650 4211 Ginkgo 2000 20140717 540150 3164650 4452 Healthy Joints 20140416 540150 3114334 4211 Ginkgo 2000 20140416 540150 3114334 4452 Healthy Joints 20140819 540258 3182987 1513 Super B 50 20140819 540258 3182987 1616 Super C 20140819 540258 3182987 2123 Zinc Plus 20140819 540258 3182987 2171 Magnesium Plus 20140522 540258 3132182 1513 Super B 50 20140522 540258 3132182 2123 Zinc Plus 20140522 540258 3132182 3324 Hair Skin & Nails Nutrition 20140522 540258 3132182 3533 Women's Daily Vitality Multi In the above data set, Customer - 540150 bought Gingko & Healthy Joints twice. But in the output I would like to see only the very last Gingko & Healthy Joints they bought (i.e. Order Number 3164650). So Order 3114334 should be ignored Similarly for Customer - 540258, I would like to get Super B 50, Super C, Zinc, Magnesium, Hair Skin & Nails and Women's Daily in the output. So it ignores when the previous time the first 4 products were bought and only retains the very last time a SKU was bought , thereby taking 4 SKU's from the last order and 2 SKU's from the previous order So I would want the output to look like ProdRunDateKey CustCode OrderNumber ProdCode LongDescription 20140717 540150 3164650 4211 Ginkgo 2000 20140717 540150 3164650 4452 Healthy Joints 20140819 540258 3182987 1513 Super B 50 20140819 540258 3182987 1616 Super C 20140819 540258 3182987 2123 Zinc Plus 20140819 540258 3182987 2171 Magnesium Plus 20140522 540258 3132182 3324 Hair Skin & Nails Nutrition 20140522 540258 3132182 3533 Women's Daily Vitality Multi
... View more