I am attempting to calculate the number of members(customers) who have met threshold criteria to be bumped up to the next tier of membership and the date on which they met the criteria.
The criteria are:
- Visit 5 or more locations their membership
- Spend at least $1500
Using my code below, I'm able to create a new dataframe containing members who meet the above criteria, however, I'm stuck when it comes to recording the date on which they were met.
The code I am using is:
criteria_met <- member_bookings %>%
filter(visit_date >= member_join_date, visit_date <= expiry_date) %>%
group_by(member_number) %>%
summarise(sum_nett = sum(new_total_nett),
locs_visited = n_distinct(location_id),
crit_met = as.logical(if_else(sum_nett >= 1500 & parks_visited >= 5, 1, 0))) %>%
filter(crit_met == TRUE)
I attempted to use mutate(date_met = max(visit_date))
however, as I should have known, this only returned their most recent visit and not the visit date on which the criteria were met.