COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: m23 on 03 Feb 2008 09:15:59 PM

Title: How to get previous year
Post by: m23 on 03 Feb 2008 09:15:59 PM
Hi,
I have a boolean style variable and I am trying to setup the expression so that it is database_field = current year minus 1. How do I get the current year minus 1?

ie currently I have [Query].[Field]=2007

I would rather not harcode the 2007 though as otherwise I will need to update it every year. Does any one know what to replace this harcoding with?
Title: Re: How to get previous year
Post by: aji136 on 04 Feb 2008 01:03:12 AM
I would use extract(year, current_date) - 1 to get previous year. Not sure if this is what you want...
Title: Re: How to get previous year
Post by: Suraj on 04 Feb 2008 02:48:23 PM
As suggested by aji136,
The following expression should work for your purpose:
[Query].[Date Field]=extract(year, current_date) - 1
Title: Re: How to get previous year
Post by: m23 on 04 Feb 2008 06:35:46 PM
I tried putting this in but it gives me an error.

RSV-VAL-0002 Invalid Expression [Query].[Date Field]=extract(year, current_date) - 1 CRX-YXX Parsing error on or around position 42 in the expression "[Query].[Date Field]=extract(year"

or if I run the report

Parsing error on or around position 42 in the expression: "[Query].[Date Field]=extract(year"

Any other ideas?
Title: Re: How to get previous year
Post by: Suraj on 05 Feb 2008 09:30:26 AM
parsing error means you have a ) or , or some characters that are either missing or more than needed.
check the expression.
Title: Re: How to get previous year
Post by: m23 on 05 Feb 2008 06:47:58 PM
My expression is exactly as per below

[Cost breakdown].[EFFECTIVE_YEAR]=extract(year, current_date) - 1

position 42 is extract(year, current_date) - 1.

This is in a style variable ie

view -> variables
Then I select a Boolean variable and enter the expression. Alot of the functions such as extract do not seem to be available for me to use here. Surely there must be some way to do it though?

Title: Re: How to get previous year
Post by: Lokki on 06 Feb 2008 02:40:36 AM
try
[Cost breakdown].[EFFECTIVE_YEAR]=extract(year; current_date) - 1
Title: Re: How to get previous year
Post by: sandhya on 06 Feb 2008 03:11:58 AM
first create a data item in ur query with expression
extract(year, current_date) - 1
Then use this data item while comparing in boolean variable


Title: Re: How to get previous year
Post by: m23 on 06 Feb 2008 08:09:48 PM
Thanks Sandhya, I finally got it working using your suggestion. :)