i've this use case where i would like to group transactions per person into groups based on the difference in dates between transactions. See table below on example dataset:
|Person ID||Transaction ID||Transaction_Item||Transacted Date||Grouping|
The grouping column is what i wish to achieve. Basically transactions are sorted in ascending transacted date and if they are within 30 days of each other, they will be grouped together. If not they are not grouped together. Currently i'm able to get the number of days between each transaction and used a for loop to achieve that. However i'm wondering if there is a more efficient way of doing this as this method takes too long when dealing with large number of transactions.
Hopefully someone here can give me advice, thanks.