COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Framework Manager => Topic started by: gordread on 03 Sep 2014 03:37:26 PM

Title: Is it possible to use an 'if' statement when calculating a value?
Post by: gordread on 03 Sep 2014 03:37:26 PM
I'm pretty new to framework manager, so I have a pretty basic question, and I haven't been able to find a clear answer, so hopefully someone here can help.

I am trying to create a calculated value (PreviousRun) using the following logic:

if ([Calculated_Values].[TodayDayOfWeek]  = 1 ) then
   (PreviousRun = _add_days(current_date, -2))
else
   (PreviousRun = _add_days(current_date,-1))

Basically if 'TodayDayOfWeek' is Monday, then set the value to 2 days ago, otherwise, set the value one day ago.

My question: is this even possible?  If so, what is the syntax?  If not, any suggestions?

Thanks,

Gordon
Title: Re: Is it possible to use an 'if' statement when calculating a value?
Post by: MFGF on 04 Sep 2014 03:01:00 AM
Quote from: gordread on 03 Sep 2014 03:37:26 PM
I'm pretty new to framework manager, so I have a pretty basic question, and I haven't been able to find a clear answer, so hopefully someone here can help.

I am trying to create a calculated value (PreviousRun) using the following logic:

if ([Calculated_Values].[TodayDayOfWeek]  = 1 ) then
   (PreviousRun = _add_days(current_date, -2))
else
   (PreviousRun = _add_days(current_date,-1))

Basically if 'TodayDayOfWeek' is Monday, then set the value to 2 days ago, otherwise, set the value one day ago.

My question: is this even possible?  If so, what is the syntax?  If not, any suggestions?

Thanks,

Gordon

Hi Gordon,

You're almost there! You just need to realise that the expression itself controls the value returned by the calculated item, so the 'PreviousRun =' parts are not required - that part is inherent.

Try this:

if ([Calculated_Values].[TodayDayOfWeek]  = 1 ) then
   (_add_days(current_date, -2))
else
   (_add_days(current_date,-1))

Cheers!

MF.
Title: Re: Is it possible to use an 'if' statement when calculating a value?
Post by: gordread on 04 Sep 2014 08:55:22 AM
So close. :)  As soon as I took out the assignment it worked just fine.

Thanks MF.

Gordon