COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: N013 on 14 Nov 2008 07:57:10 AM

Title: Changing the sign of a value
Post by: N013 on 14 Nov 2008 07:57:10 AM
I am trying to change the sign of a data item (revenue amount). Currently, the value is a credit(negative) and I need the value to appear as positive for the report (if it is negative) and if it appears as a positive the value should be a negative.

The easiest way I thought would be to multiply the data item by a -1. However, the expression editor does not validate.

Also, I tried the abs() function but that will not give me a negative if the value is positive.

Anythoughts or comments would be greatly appreciated!

Title: Re: Changing the sign of a value
Post by: Stejawh on 14 Nov 2008 08:09:45 AM
Multiplying by -1 is a way of doing this.  What is the expression that doesn't validate.  There must be something else wrong with the expression.

Cheers,

Steve
Title: Re: Changing the sign of a value
Post by: N013 on 14 Nov 2008 08:15:13 AM
This does not work...


(IF ([Period Amounts].[Period Amounts - All].[Fiscal Year] = ?Fiscal Year?)
Then
(IF ([ObjectCodeGroup] = 'Revenue')
Then
([Period Amounts].[Period Amounts - All].[YTD Amount - Period 12]*-1)
Else
([Period Amounts].[Period Amounts - All].[YTD Amount - Period 12])
)
Else
(0)
)


However, this does.


(IF ([Period Amounts].[Period Amounts - All].[Fiscal Year] = ?Fiscal Year?)
Then
(IF ([ObjectCodeGroup] = 'Revenue')
Then
(abs([Period Amounts].[Period Amounts - All].[YTD Amount - Period 12]))
Else
([Period Amounts].[Period Amounts - All].[YTD Amount - Period 12])
)
Else
(0)
)

Title: Re: Changing the sign of a value
Post by: N013 on 14 Nov 2008 08:27:45 AM
This seems to work.

(IF ([Period Amounts].[Period Amounts - All].[Fiscal Year] = ?Fiscal Year?)
Then
(IF ([ObjectCodeGroup] = 'Revenue')
Then
(-[Period Amounts].[Period Amounts - All].[YTD Amount - Period 12])
Else
([Period Amounts].[Period Amounts - All].[YTD Amount - Period 12])
)
Else
(0)
)


Adding the negative sign in from of the data item seems to convert the sign like I want. Can you confirm this will give the desired result?
Title: Re: Changing the sign of a value
Post by: Stejawh on 14 Nov 2008 09:27:48 AM
Hi,
Not knowing your data it's hard to say if this latest expression will perform how you want it to.  have you tested against a Negative and a Positive? if so does it convert ok?

I'm interested to know why the first example doesn't work.  Can you provide me with the error?

Thanks,

Steve