This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
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 |
Solved! Go to Solution.
The attached workflow should do the trick! If you sort by the customer ID and then the Visit date, you can then creating a running total of consecutive visits using the Multi Row Formula. Then using the summarize tool you can get the maximum number of consecutive and the most recent visit.
Hope this helps and let me know if you have any questions!
See attached for a possible solution! Uses a few Multi-Row tools to determine if a date is consecutive to the one before & after, and then a few Summarize tools to group/sum/max to get the results you desire... hope that helps!
Cheers,
NJ
EDIT: Though @nick_ceneviva solution, while the same concept, is way more streamlined... you should use that one :)
Thanks for the reply Nick! I'm running version 11.0.5.26351 It wouldn't let me open the workflow
Thank you both for replying! Nicole I wasn't able to open yours as well. However, Nick's is working.
Nick,
In the multi-line formula I can't tell how its determining that the new consecutive days count is greater or less than the existing. (It seems to be working though). I'm just trying to learn. can you explain?
So its not actually checking against other consecutive streaks. It is just a running total and then the summarize tool takes the max consecutive days. So the output would look something similar to this coming out of the Multi Row Formula tool:
Date | Consecutive Visits (From Multi Line) |
1/1/2017 | 1 |
1/2/2017 | 2 |
1/4/2017 | 1 |
1/5/2017 | 2 |
1/6/2017 | 3 |
1/7/2017 | 4 |
1/15/2017 | 1 |
1/16/2017 | 2 |
1/17/2017 | 3 |
If all of the above records are for the same customer, the max consecutive visits is 4. Hope that helps!
This worked for me, thanks!