Hi all,
I need help grouping data on a consumer level based on if they received communications within a 30 day window, with the 30 days starting from the 1st communication. It is meant to study how effective sending multiple communications is to a Consumer. The challenge is to create a differentiating group - if the same consumer receives another communication 30 days from the 1st communication. The example raw data looks like this:
| customerid | comm_date | comm_type |
| 1234 | 1/1/2022 | Email |
| 1234 | 1/2/2022 | Direct |
| 1234 | 1/15/2022 | Email |
| 1234 | 2/4/2022 | Email |
| 1234 | 2/5/2022 | Direct |
| 1234 | 3/10/2022 | Direct |
| 2345 | 1/1/2022 | Email |
| 2345 | 2/5/2022 | Email |
| 2345 | 2/6/2022 | Direct |
The first step is to group together the following records and then have them assigned to a RecordID.

The 2/4/22 Email communication falls +30 days from the very first 1/1/22 Email Communication for Consumer "1234" and is thus, a "new" group for that consumer. Then the 3/10/22 Direct communication is another group because 3/10 is +30 days from 2/4/2022 in the previous group. I am having a bit of a trouble dynamically creating this min_comm_date based on each group and starting the 30 day window from that point on.
The final dataset I wish to achieve, looks something like this:
| customerid | min_comm_date | max_comm_date | no_touches | Email | Direct | RecordID |
| 1234 | 1/1/2022 | 1/15/2022 | 3 | 2 | 1 | 1 |
| 1234 | 2/4/2022 | 2/5/2022 | 2 | 1 | 1 | 2 |
| 1234 | 3/10/2022 | 3/10/2022 | 1 | 0 | 1 | 3 |
| 2345 | 1/1/2022 | 1/1/2022 | 1 | 1 | 0 | 4 |
| 2345 | 2/5/2022 | 2/6/2022 | 2 | 1 | 1 | 5 |
If this isn't explain well, please let me know if you have any questions. Thanks all for your help!