I have the following table tblPurchases and structure:
I would like to be able to do the following:
create Field - Episode
A gap of 180 or more days in between consecutive purchase dates is considered the start of a new episode.
Whereby my output file would look like this:
Thanks in advance for any help on this.
Code:
tblPurchasesID CustomerID DatePurchased
1 177405 4/1/2005
2 177405 7/23/2005
3 177405 7/30/2005
4 177405 1/24/2006
5 177405 6/30/2006
6 177405 7/24/2006
7 177405 7/29/2006
8 177405 2/20/2007
9 177405 3/30/2007
10 177405 4/13/2007
11 177405 7/10/2007
12 177405 10/2/2007
13 177405 11/14/2007
14 177405 12/12/2007
15 220391 1/19/2005
16 220391 2/2/2005
17 220391 2/25/2005
18 220391 3/18/2005
19 220391 7/5/2005
20 220391 6/7/2006
21 220391 7/11/2006
22 220391 8/11/2006
23 220391 9/25/2006
26 220391 4/2/2007
27 220391 5/23/2007
28 220391 8/10/2007
29 220391 8/24/2007
create Field - Episode
A gap of 180 or more days in between consecutive purchase dates is considered the start of a new episode.
Whereby my output file would look like this:
Code:
tblPurchasesID CustomerID DatePurchased Interval Episode
1 177405 4/1/2005 0 1
2 177405 7/23/2005 113 1
3 177405 7/30/2005 7 1
4 177405 1/24/2006 178 1
5 177405 6/30/2006 157 1
6 177405 7/24/2006 24 1
7 177405 7/29/2006 5 1
8 177405 2/20/2007 206 2
9 177405 3/30/2007 38 2
10 177405 4/13/2007 14 2
11 177405 7/10/2007 88 2
12 177405 10/2/2007 84 2
13 177405 11/14/2007 43 2
14 177405 12/12/2007 28 2
15 220391 1/19/2005 0 1
16 220391 2/2/2005 14 1
17 220391 2/25/2005 23 1
18 220391 3/18/2005 21 1
19 220391 7/5/2005 109 1
20 220391 6/7/2006 337 2
21 220391 7/11/2006 34 2
22 220391 8/11/2006 31 2
23 220391 9/25/2006 45 2
26 220391 4/2/2007 189 3
27 220391 5/23/2007 51 3
28 220391 8/10/2007 79 3
29 220391 8/24/2007 14 3
Thanks in advance for any help on this.