COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: cognosmanager on 30 Apr 2012 05:05:03 AM

Title: if then
Post by: cognosmanager on 30 Apr 2012 05:05:03 AM
Hi All,

I have a report in which i have Name, Column A, Column B, Column C and Date.

Name        Column A       Column B        Column C                  Date
XYZ              250                                        265                   Dec 31 2011   
XYZ               0                                           196                  June 30 2011

And made Query Calculation column in which the condition is "if ((to_char ([Date],'mm/dd') in ('12/31') and [Column A] >0) and (to_char ([DATE],'mm/dd') in ('06/30') and [Column A] = 0)) then ([Column C]) else ([Column B])".

If both the conditions are satisfied then it should show Column C value but instead it is giving value from Column B.

Please help me out.
Title: Re: if then
Post by: wyconian on 30 Apr 2012 05:46:32 AM
Hi

Think you've gone a bit astray in your logic.  You calcualtion says if date = 12/31 and date = 06/30 then column c else column b

The date can't be both 12/31 and 06/30 which is why you're getting column B coming back.

Try something like
(if (to_char([Date].'mm/dd') in ('12/31','06/30') and ([Column A] = 0) then ([Column C]) else ([Column B])

Good luck
Title: Re: if then
Post by: cognosmanager on 30 Apr 2012 08:40:14 AM
Hi,

What I want is that a person will be pulled if both the dates are satified i.e. for 31 dec 2011, column A should be greater than 0 and for 30 june 2011, column A should be equal to zero. If both of them are satisfied then value of Column C should come up.
Title: Re: if then
Post by: Lynn on 30 Apr 2012 09:19:19 AM
I'll take a shot at it...


case
  when to_char([Date],'mm/dd') in ('12/31') and [Column A] > 0
    then [Column C]
  when to_char([DATE],'mm/dd') in ('06/30') and [Column A] = 0
    then [Column C]
  else [Column B]
end
Title: Re: if then
Post by: wyconian on 30 Apr 2012 09:39:25 AM
Cognos manager I understand what you're asking (I think), bear in mind that the filter will be applied to each record in turn.  I would have thought that you can't have 1 record where the date is 12/31 and 06/30 (it could be one or the other but not both), that's why you were getting the wrong column coming back.

Lynne's calc does the same thing as mine (I think) but is probably easier to read.

As an aside if you've only got one value to compare things to it's faster to do = than in.
Title: Re: if then
Post by: Lynn on 30 Apr 2012 10:03:28 AM
Filter??  :o

I think this is a query calculation that looks at the date column and column A....it then returns either column C or B depending on the conditions.

A single date column cannot be two values on the same row, but it can contain different values on different rows. The case statement considers two conditions that result in column C being selected and uses column B for any other condition.

Wyconian, your expression says column A must be *equal* to zero for both dates, but the requirement (I think) is for A to be greater than zero for 12/31 and equal to zero for 6/30.

Signed,
Lynn (without an "e")  ;)
Title: Re: if then
Post by: wyconian on 30 Apr 2012 11:11:10 AM
Sorry Lynn I missed that :)
Title: Re: if then
Post by: cognosmanager on 30 Apr 2012 11:09:54 PM
Thanks for the help guys.
Title: Re: if then
Post by: cognostechie on 30 Apr 2012 11:52:19 PM
Quote from: cognosmanager on 30 Apr 2012 11:09:54 PM
Thanks for the help guys.

You mean thanks for the help wyconian and Lynn ?  ;D
Title: Re: if then
Post by: Lynn on 01 May 2012 07:06:00 AM
Too funny!  ;D

I say "guys" all the time without regard to gender of those in the group I am addressing. I haven't encountered any women who are bothered by this.

I wonder what would happen if I started saying "gals" all the time instead?  ;)
Title: Re: if then
Post by: MFGF on 01 May 2012 08:28:04 AM
Quote from: Lynn on 01 May 2012 07:06:00 AMI wonder what would happen if I started saying "gals" all the time instead?  ;)

I would assume it was the weekend if you were referring to me :)
Title: Re: if then
Post by: jive on 02 May 2012 09:39:19 AM
Hi , instead of havin an 'AND' in your if-then-else replace it by a 'OR'  like

"if ((to_char ([Date],'mm/dd') in ('12/31') and [Column A] >0) OR (to_char ([DATE],'mm/dd') in ('06/30') and [Column A] = 0)) then ([Column C]) else ([Column B])".

And it will work