Lets test steps 1,2,3 (calculation without specific animals).
I will not attach the file this time, so
1) sort your data by "Date" Oldest to Newest
2) add "01.02.2017" in cell P7, to ensure EndPeriod for the code
Try to run code below, my results is in attached file.
If you'll confirm that results seems OK, than we can implement one more criteria for each animal.
My assumption: code calculates correct,I've manually checked first month and last month (for the last month 30 days and 90 days amounts are the same - as they should be).
One thing to clarify: for the logic with specific animals - in case we found first user #123 transaction for the cat in August then in +30 and +90 we also should looking only for cat transactions by user #123? Or should we look at all this user transactions?