Rolling previous 12 month count that spans into previous year.

Jim McWilliams
edited 05/16/23 in Formulas and Functions

I have a sheet that is logging customer complaint information. One column is recording the date of the complaint. One a second sheet I have 12 rows, one for current month, and one for each of the previous 12 months. I want that to automatically populate a cell in each of those 12 rows with a count of the total number of complaints.

i.e. this month has a running total of the "current month" May, then next to it is "1 month ago" April, then March, etc. When June begins, it will populate the "current month" field, and May will populate "1 month ago, etc.

I tried:

Current month - 1 (aka last month)

=COUNTIFS({Customer Complaint Log Range 3}, AND(IFERROR(MONTH(@cell), 0) = MONTH(IFERROR(DATE(YEAR(TODAY()), MONTH(TODAY()) - 1, 1), DATE(YEAR(TODAY()) + 1, MONTH(TODAY()) - 11, 1))), IFERROR(YEAR(@cell), 0) = YEAR(IFERROR(DATE(YEAR(TODAY()), MONTH(TODAY()) - 1, 1), DATE(YEAR(TODAY()) + 1, MONTH(TODAY()) - 11, 1)))))

This seemed to work by adjusting the bold number for each previous month...2 months ago became -2 and -10,2.

It stopped working when the data referenced was from December of 2021, which looked like this (being 5 months ago):

=COUNTIFS({Customer Complaint Log Range 3}, AND(IFERROR(MONTH(@cell), 0) = MONTH(IFERROR(DATE(YEAR(TODAY()), MONTH(TODAY()) - 5, 1), DATE(YEAR(TODAY()) + 1, MONTH(TODAY()) - 7, 5))), IFERROR(YEAR(@cell), 0) = YEAR(IFERROR(DATE(YEAR(TODAY()), MONTH(TODAY()) - 5, 1), DATE(YEAR(TODAY()) + 1, MONTH(TODAY()) - 7, 5)))))

Not sure if it's an issue with the year reference or something else...any ideas are appreciated.


Thanks,

Jim

Answers

Help Article Resources

Want to practice working with formulas directly in Smartsheet?

Check out the Formula Handbook template!