I have a large set of customer data, and I need to get the longest number of consecutive visited days for each customer, as well as, the date of their most recent visit. The most recent visit is easy, but I'm having trouble calculating the longest consecutive visit.
For instance a customer might have visits for Jan 1st 2017 through Jan 9th 2017 (9 consecutive days) then not visit again until Feb 1st 2017 and visit for 10 days (Feb 1st - 10th) That same customer might then miss a few days and then visit again for 3 consecutive days. (Feb 20th - Feb 20rd)
Essential I would like to end up with three fields Cust ID | Most consecutive visits | Last visit
Data looks like this
Visit Date | Cust ID |
01/01/2017 | 1111 |
01/01/2017 | 5555 |
01/02/2017 | 5555 |
01/03/2017 | 1111 |
01/04/2017 | 1111 |
01/04/2017 | 5555 |
01/04/2017 | 9999 |
01/05/2017 | 1111 |
01/06/2017 | 1111 |
01/06/2017 | 5555 |
01/06/2017 | 9999 |
01/07/2017 | 1111 |
01/07/2017 | 5555 |
01/07/2017 | 9999 |
01/08/2017 | 1111 |
01/08/2017 | 5555 |
01/09/2017 | 1111 |
01/10/2017 | 5555 |
Cust ID | Longest Consecutive Visit | Last Visit |
1111 | 7 | 01/09/2017 |
5555 | 3 | 01/10/2017 |
9999 | 2 | 01/07/2017 |