COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: niahanth on 01 Feb 2016 10:21:38 AM

Title: last_day function in cognos
Post by: niahanth on 01 Feb 2016 10:21:38 AM
Hi

I have a requirement in which i need to last day of the previous week in the report.

For example if i run the report today i need to show the date as 1/31/2016

I am writing using last_day function but i am getting error.

I need to calculate last_day(sysdate ,-1 week). It calculates the last day of the week and subtracts 1 week and displays the date.

Thanks
Title: Re: last_day function in cognos
Post by: MFGF on 01 Feb 2016 11:16:43 AM
Quote from: niahanth on 01 Feb 2016 10:21:38 AM
I am writing using last_day function but i am getting error.

What expression are you using? What error do you get? Are you using a relational or a dimensional package? When does a week start and end - Sunday to Saturday or Monday to Sunday (or something else?)

MF.
Title: Re: last_day function in cognos
Post by: niahanth on 01 Feb 2016 12:22:49 PM
Hi

I am using relational model.

The week starts from Monday and ends on sunday.

I am wriritng
last_day((sysdate)-7 days))

I am getting the following error

V5 syntax error found for data item 'Data Item1' of query 'Query1', invalid token "sysdate" found after "last_day((".

Thanks
Title: Re: last_day function in cognos
Post by: schrotty on 01 Feb 2016 02:50:20 PM
Hi,

Instead of sysdate try current_date (it's the cognos build-in-function).

The other syntax also doesnt look like cognos-syntax

I'd use something like
_add_days( current_date, _day_of_week(current_date,1)*-1 )

Schrotty
Title: Re: last_day function in cognos
Post by: BigChris on 02 Feb 2016 01:59:45 AM
As an aside, you might want to consider building a Calendar table for your data warehouse. In there you can store dates for yesterday, start of week, start of last week, end of last week, start date of current financial period etc.