Quantcast
Channel: Data Preparation & Blending discussions
Viewing all articles
Browse latest Browse all 4999

Count consecutive days

$
0
0

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 DateCust ID
01/01/20171111
01/01/20175555
01/02/20175555
01/03/20171111
01/04/20171111
01/04/20175555
01/04/20179999
01/05/20171111
01/06/20171111
01/06/20175555
01/06/20179999
01/07/20171111
01/07/20175555
01/07/20179999
01/08/20171111
01/08/20175555
01/09/20171111
01/10/20175555

 

Cust IDLongest Consecutive VisitLast Visit
1111701/09/2017
5555301/10/2017
9999201/07/2017

 

 


Viewing all articles
Browse latest Browse all 4999

Trending Articles