COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: nrhodes00 on 31 Aug 2011 02:21:40 PM

Title: why is the expression not working
Post by: nrhodes00 on 31 Aug 2011 02:21:40 PM
Not sure what i'm missing

(if ([Coverage Option 2] is missing))
then([Coverage Option 3]))

(if ([Coverage Option 3] is missing)
then ([Coverage Option 2]))

(if ([Coverage Option 2] is missing and [Coverage Option 3]is missing)
then ([Coverage Option Code]) )

else ('xxxx')
Title: Re: why is the expression not working
Post by: sir_jeroen on 31 Aug 2011 02:28:35 PM
what about:
case
when ( [c2] is missing) then ([c3])
when ( [c3] is missing) then ([c2])
when (c2 is missing and c3 is missing) then ([coc])
else ('xxxx')
end

Title: Re: why is the expression not working
Post by: MFGF on 01 Sep 2011 02:52:16 AM
Quote from: nrhodes00 on 31 Aug 2011 02:21:40 PM
Not sure what i'm missing

(if ([Coverage Option 2] is missing))
then([Coverage Option 3]))

(if ([Coverage Option 3] is missing)
then ([Coverage Option 2]))

(if ([Coverage Option 2] is missing and [Coverage Option 3]is missing)
then ([Coverage Option Code]) )

else ('xxxx')

As RA says above, but you also need to be aware that expressions get evaluated in the order in which you declare them, and once a True result is found, no further processing occurs. This would mean that you could have a situation where both Coverage Option 3 and Coverage Option 2 are missing, but the expression returns Coverage Option 3 (a null) because the first expression would evaluate as True.

You should probably rearrange the order to check for both Coverage Option 2 and Coverage Option 3 missing in the first expression:

case
when ( [Coverage Option 2] is missing and [Coverage Option 3] is missing) then ([Coverage Option Code])
when ( [Coverage Option 2] is missing) then ([Coverage Option 3])
when ( [Coverage Option 3] is missing) then ([Coverage Option 2])
else ('xxxx')
end

or alternatively:

if ([Coverage Option 2] is missing and [Coverage Option 3] is missing) then ([Coverage Option Code]) else if ([Coverage Option 2] is missing) then ([Coverage Option 3]) else if ([Coverage Option 3] is missing) then ([Coverage Option 2]) else ('xxxx')

Regards,

MF.