COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: gatorfe on 10 Jan 2014 12:45:55 PM

Title: Cast Formula Help
Post by: gatorfe on 10 Jan 2014 12:45:55 PM
We are trying to get this formula to work.  We keep getting a parse error.

if(cast([Stock Forecast].[Record Id], numeric)=2)  and cast([Stock Forecast].[Order Type], numeric) = 9)
then
([Stock Forecast].[Open Quantity] * -1)
else
[Stock Forecast].[Open Quantity]

Record ID and Order Type are varchar fields and open qty is numeric.  Thank you in advace for any suggestions!

Title: Re: Cast Formula Help
Post by: HalfBloodPrince on 11 Jan 2014 11:19:13 PM
if( cast([Stock Forecast].[Record Id], numeric)=2)  and cast([Stock Forecast].[Order Type], numeric) = 9) )
then
([Stock Forecast].[Open Quantity] * -1)
else
([Stock Forecast].[Open Quantity])
Title: Re: Cast Formula Help
Post by: Francis aka khayman on 12 Jan 2014 08:38:33 PM
check your parenthesis
Title: Re: Cast Formula Help
Post by: gatorfe on 13 Jan 2014 10:03:03 AM
Thank you for the info.  It seems to be off though.  If we just do it with one cast it works but when we add the other it does not want to work.  Any suggestions?
This is what works:if (cast([Stock Forecast].[Record Id], numeric) =2 )
then
([Stock Forecast].[Open Quantity] * -1)
else
([Stock Forecast].[Open Quantity])

Does not work:if (cast([Stock Forecast].[Record Id], numeric) =2 )
and
if (cast ([Stock Forecast].[Order Type], numeric) = 9)
then
([Stock Forecast].[Open Quantity] * -1)
else
([Stock Forecast].[Open Quantity])

Does not work:
if (cast([Stock Forecast].[Record Id], numeric) =2 )
and
cast ([Stock Forecast].[Order Type], numeric) = 9
then
([Stock Forecast].[Open Quantity] * -1)
else
([Stock Forecast].[Open Quantity])

Does not work:
if (cast([Stock Forecast].[Record Id], numeric) =2 )
and
(cast ([Stock Forecast].[Order Type], numeric) = 9)
then
([Stock Forecast].[Open Quantity] * -1)
else
([Stock Forecast].[Open Quantity])
Title: Re: Cast Formula Help
Post by: MFGF on 13 Jan 2014 10:12:40 AM
Hi,

How about:

if (cast([Stock Forecast].[Record Id], numeric) =2
and
cast ([Stock Forecast].[Order Type], numeric) = 9)
then
([Stock Forecast].[Open Quantity] * -1)
else
([Stock Forecast].[Open Quantity])

MF.