Reputation: 147
I have a list of users with dates of they visited the website. I need to calculate the first visit date for each record with the condition that if a user misses a month, it is considered new and the date should be new. How can I calculate it?
Here is an example. I need to calculate the First visit column.
Visit Date User First visit
10/15/19 User1 10/15/19
11/13/19 User1 10/15/19
01/07/20 User1 01/07/20
02/03/20 User1 01/07/20
Upvotes: 1
Views: 390
Reputation: 34355
Assuming the data is sorted by user and date as in the example:
=ArrayFormula(to_date(vlookup(row(A2:A),filter({row(A2:A),A2:A},
countifs(row(A2:A),row(A2:A)-1,B2:B,B2:B,A2:A,">"&eomonth(A2:A,-2))=0),2,true)))
If you can't assume that the data is sorted by user and date, you can try something like this:
=ArrayFormula(vlookup(filter(B2:B&text(A2:A,"YYYYMMDD"),A2:A<>""),
sort(filter({B2:B&text(A2:A,"YYYYMMDD"),A2:A},
countifs(A2:A,"<"&A2:A,B2:B,B2:B,A2:A,">"&eomonth(A2:A,-2))=0,A2:A<>""),1,1),2,true))
Upvotes: 2