COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: Hinky on 10 Nov 2010 02:22:49 PM

Title: Pulling Data for entire month prior to current month
Post by: Hinky on 10 Nov 2010 02:22:49 PM
i want to pull benefit deduction amounts for the entire month prior, grouped by employee.
This is what I am using... and it does not work... Please help :)

extract (month,[My Employees].[Main Section].[Pay Date]) = extract (month, _add_months(current_date,-1) )

Thank you kindly  :P
Title: Re: Pulling Data for entire month prior to current month
Post by: cognos10 on 10 Nov 2010 02:50:26 PM
Hello u can try the below filter


keep a simple filter saying

[My Employees].[Main Section].[Pay Date]
between

first_of_month(_add_months(current_date,-1)
and
last_of_month(_add_months(current_date,-1)


I think this should work

Thanks
Title: Re: Pulling Data for entire month prior to current month
Post by: Hinky on 11 Nov 2010 09:36:30 AM
I tried this:


[My Employees].[Main Section].[Pay Date] between first_of_month (_add_months(current_date,-1) and last_of_month (add_months(current_date,-1)


and I'm still getting an error... I'll continue to try and work with this.
Title: Re: Pulling Data for entire month prior to current month
Post by: Lynn on 11 Nov 2010 10:50:09 AM
The Cognos function for first of month and last of month have the underscore character in the beginning of the function name:

_first_of_month
_last_of_month

So unless your DBMS has a function called first_of_month then I imagine you'd get a parsing error. It is often useful to specify the error you are getting or the unexpected behavior you see. People can only guess when the question is "i get an error" or "it doesn't work".
Title: Re: Pulling Data for entire month prior to current month
Post by: Hinky on 11 Nov 2010 12:09:37 PM
I modified the query to include the underscore as mentioned. This is the error that I am getting:

   Parsing error before or near position: 143 of: "[My Employees].[Main Section].[Pay Date] between _first_of_month (_add_months(current_date,-1) and _last_of_month (add_months(current_date,-1)"

Thanks
Title: Re: Pulling Data for entire month prior to current month
Post by: Lynn on 11 Nov 2010 01:47:47 PM
A good way to troubleshoot filter expressions like this is to create data items first to get the syntax figured out and ensure they are returning values you expect.

For example, create a data item in the query and work out the first of month portion.

As soon as you do that you can see there are two opening parenthesis and only one closing parenthesis. Looks like the same issue on the last of month side.
_first_of_month (_add_months(current_date,-1)
should be
_first_of_month (_add_months(current_date,-1))

Once you have the two items working as expected you can plop them into your filter and take it from there. Hope this helps
Title: Re: Pulling Data for entire month prior to current month
Post by: Hinky on 12 Nov 2010 09:35:47 AM
Thanks Lynn! This worked perfectly!! ;)