I'm trying to find the sum of amount for an 'ID' trailing 365 days from the 'DT'. Below is a sample from the data I'm working on. The below table consists of dates when purchase was made , id and the amount. I wanted to calculate amount spent by an id trailing 365 days from the 'DT'. Any help on this will be appreciated. Thanks.