Hi friend even this code works for me I am not getting all the customer having data as below . **week\_no Customer\_ID purchase\_yn**
 201728 87697 1
 201728 87697 1
 201728 87697 1
 201732 87697 1
 201733 87697 0
 201742 87697 0
 201743 87697 1  

I want out put like below . Number of distinct weeks upto second purchase made
 Customer ID No of weeks 
 87697 2