COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: M1ndbender on 18 Oct 2021 10:53:40 AM

Title: Rolling 12 weeks
Post by: M1ndbender on 18 Oct 2021 10:53:40 AM
Hi there,

I am stuck trying to find a way to only return the previous 12 weeks worth of data that will continue to work when they span multiple years. If I was to run it in Jan or Feb I would need it to pull back the 2022 data as well as the rest of the 12 weeks that fall in 2021.

Any help would be appreciated
Title: Re: Rolling 12 weeks
Post by: BigChris on 19 Oct 2021 02:21:48 AM
Ok, depending on what you need, and your structures etc., you could probably use something along the lines of:

[YourDateField] between _add_days(current_date,-(84 + _day_of_week(current_date,1)) and _add_days(current_date,-day_of_week(current_date,1)

Do some testing on the day of week function - I've just written that off the top of my head, so it might not be quite right.
Title: Re: Rolling 12 weeks
Post by: M1ndbender on 19 Oct 2021 06:51:31 AM
Thank you. I will play around with it. For my own curiosity - what does the 84 do?
Title: Re: Rolling 12 weeks
Post by: BigChris on 19 Oct 2021 07:28:29 AM
12 * 7 = 84   :D
Title: Re: Rolling 12 weeks
Post by: M1ndbender on 19 Oct 2021 09:12:09 AM
right   duh  lol
Title: Re: Rolling 12 weeks
Post by: M1ndbender on 19 Oct 2021 02:49:23 PM
That worked. Thank you very much. I can't seem to find how to close the ticket but this one can be considered closed