COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: gats1527 on 21 Jan 2021 12:43:48 PM

Title: Filter report to pull prior month when its from a previous year
Post by: gats1527 on 21 Jan 2021 12:43:48 PM
We are trying to create a report that will, when scheduled, pull the prior months expense data but for the first of the year, i need to have the report pull December 2020 data.  I can manually set the filter to pull the year 2020 and the month 12, but when scheduled, i need the filter to execute automatically.

Any thoughts on how to easily accomplish this?

Thank you

Tom
Title: Re: Filter report to pull prior month when its from a previous year
Post by: MFGF on 21 Jan 2021 01:03:55 PM
Quote from: gats1527 on 21 Jan 2021 12:43:48 PM
We are trying to create a report that will, when scheduled, pull the prior months expense data but for the first of the year, i need to have the report pull December 2020 data.  I can manually set the filter to pull the year 2020 and the month 12, but when scheduled, i need the filter to execute automatically.

Any thoughts on how to easily accomplish this?

Thank you

Tom

Hi,

Are you using a relational package or a dimensional package? The solution is different for each.

If it's relational, then something like:

(extract(month, current_date) = 1 AND [Your Year item] = extract(year, current_date)-1 AND [Your Month item] = 12) OR (extract(month, current_date) > 1 AND [Your Year item] = extract(year, current_date) AND [Your Month item] = extract(month, current_date)-1)

If it's dimensional, then use a dimensional expression in your report that uses a lag() function based on the current month member of the month level.

Cheers!

MF.
Title: Re: Filter report to pull prior month when its from a previous year
Post by: gats1527 on 21 Jan 2021 01:50:38 PM
thank you.  this is exactly what i needed the output to be
Title: Re: Filter report to pull prior month when its from a previous year
Post by: BigChris on 21 Jan 2021 06:03:26 PM
You might be able to do something simpler than this:
Quote(extract(month, current_date) = 1 AND [Your Year item] = extract(year, current_date)-1 AND [Your Month item] = 12) OR (extract(month, current_date) > 1 AND [Your Year item] = extract(year, current_date) AND [Your Month item] = extract(month, current_date)-1)

[Your Date Item] between _first_of_month (_add_months(current_date,-1)) and _last_of_month(_add_months(current_date,-1))

It all depends on your data really and the structures you're using...many ways to skin a cat and all that  :D