COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: k2 on 20 Jul 2010 08:43:30 AM

Title: Displaying Previous Month Data
Post by: k2 on 20 Jul 2010 08:43:30 AM
I have a report which needs to display the values for month selected by the user via value prompt and the previous month. For example, if the user selects 'December 2009' via value prompt. List Report should display the value for 'December 2009' along with 'November 2009'. In order to achieve this ,I have tried with the following condition for the data item 'Selected Month -1'but it is displaying the same value as 'Selected Month', no change.

[Selected Month] --> [Amount]

[Selected Month -1] -->

if ([Dates].[Days].[Date]=?Period?)

then (total([Amount] for _add_months([Dates].[Days].[Date],-1)))

else (0)


[Dates].[Days].[Date]=?Period? --> is the filter condition for prompt.

Please let me know, where I went wrong. It would be a great help. Thanks 
Title: Re: Displaying Previous Month Data
Post by: blom0344 on 20 Jul 2010 09:52:16 AM
[Selected Month -1] -->



CASE WHEN
[Dates].[Days].[Date]
between
_first_of_month(_add_months(?Period?,-1))
and
_last_of_month(_add_months(?Period?,-1))
THEN
[amount]
ELSE
(0)
END


assuming ?Period?  relates to a date
set aggregate as total
Title: Re: Displaying Previous Month Data
Post by: k2 on 20 Jul 2010 04:26:24 PM
Thanks for the response. Data item was aggregated as Total but no luck!!!
Title: Re: Displaying Previous Month Data
Post by: Mpotla on 20 Jul 2010 09:23:38 PM
Hi,
Use the below case stmt to aggregate the values for  selected month and previous month of it.
its small modification to the above reply.



CASE WHEN
[Dates].[Days].[Date]
between
_first_of_month(_add_months(?Period?,-1))
and
_last_of_month(?Period?)
THEN
[amount]
ELSE
(0)
END

Regards,
Potla
Title: Re: Displaying Previous Month Data
Post by: mvjcognos on 21 Jul 2010 01:20:20 AM

u can try this also

if to_date(date key,'YYYYMMDD') between _first_of_month(_add_months(?date?,-1) and ?date? then (sales quantity) else (0)