COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: ambuj2k50 on 12 Oct 2012 03:51:15 AM

Title: Previous and Next two month data
Post by: ambuj2k50 on 12 Oct 2012 03:51:15 AM
I need to design a chart report where the revenue of the starting promotion start month and the previous two months and next two months should be shown.

what would be the code to find previous 2 months and next two months by using cognos functions ?
Title: Re: Previous and Next two month data
Post by: blom0344 on 12 Oct 2012 06:09:48 AM
_months_between   function
Title: Re: Previous and Next two month data
Post by: ambuj2k50 on 14 Oct 2012 11:38:07 PM
Thanks a lot Blom i ll give it a try :)
Title: Re: Previous and Next two month data
Post by: ambuj2k50 on 15 Oct 2012 12:16:31 AM
The _months_between function returns a integer value either in +ve/-ve by taking two timestamp parameters.

Exactly what i need is

Query1 contains

Promotion
Product
Planned revenue
Revenue
Month

Query2 Contains

Planned revenue
Revenue
Product
Month

Query 3 is Join between query 1 and 2

Product
Month
Planned Revenue
Revenue

I need to apply a filter in Query 3 so that only data for the 5 months (Promotion month+previous 2 months+ after 2 months) data will be shown.

Please sugest how to achieve that.
Thanks in advance

Title: Re: Previous and Next two month data
Post by: ambuj2k50 on 15 Oct 2012 12:20:01 AM
Attaching the XML.
Title: Re: Previous and Next two month data
Post by: blom0344 on 15 Oct 2012 02:10:16 AM
That would depend on the definition of month..  If you only use the 12 valued range:  1-12 / Jan-Dec then  calculations are a real pain.  If you take - for instance - the first / last day of the month (as date) into you model, then temporal calculations become much easier. The best approach is to have a dataitem that contains the month representation and another one to calculate with..
Title: Re: Previous and Next two month data
Post by: ambuj2k50 on 15 Oct 2012 03:10:59 AM
i tried with the filter with expression

cast([Query2].[Month],timestamp) between (_add_months((cast([Query1].[Month],timestamp),-2) and (_add_months((cast([Query1].[Month],timestamp),2)

But its giving the following error

An error occurred while performing operation 'sqlOpenResult' status='-28'.
Title: Re: Previous and Next two month data
Post by: blom0344 on 15 Oct 2012 07:54:10 AM
In your case what does [month] represent?  Integer (1-12) , String, Date?
Title: Re: Previous and Next two month data
Post by: ambuj2k50 on 15 Oct 2012 11:42:11 PM
String
Title: Re: Previous and Next two month data
Post by: blom0344 on 16 Oct 2012 03:07:39 AM
like what  :o?  If it represents a date format you can use it to cast to date/timestamp.
Title: Re: Previous and Next two month data
Post by: ambuj2k50 on 16 Oct 2012 03:12:44 AM
Resolved the issue by using Month(numeric) data item instead of Month data items.
Anyways...Thanks a lot for helping.
Title: Re: Previous and Next two month data
Post by: blom0344 on 16 Oct 2012 03:31:26 AM
If you mean the numeric values running from 1 -12 then you will run into issues transcending years. By the way, the idea of a peer-to-peer forum is to post the solution if a case is resolved. This is to ensure other developers can benefit from a topic (discussion)
Title: Re: Previous and Next two month data
Post by: ambuj2k50 on 22 Oct 2012 02:58:11 AM
RESOLVED

Attaching the xml of the report (with sample package).