COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: et21 on 12 Jul 2022 05:50:39 PM

Title: IF Else Statement on Parameter
Post by: et21 on 12 Jul 2022 05:50:39 PM
Hi all i recently tried to use if statement on my parameter but somehow its always give me error no matter what I change. I even tried case as well but somehow its got the same error.

case
when (?Parameter?) = 'Yes'
then [Data Item] = 'Yes'
else then [Data Item]
end

Can someone point out my mistake please
Title: Re: IF Else Statement on Parameter
Post by: bus_pass_man on 12 Jul 2022 06:09:41 PM
Here is the syntax of a case function.

case
when [country] = 'canada' then ([list price] * 0.60)
when [countrycode] > 100 then [list price] * 0.80
else [list price]
end

In general some information which could help troubleshooting include:
What does the error message say? What changes do you make?   Are there any variations in what the error messages say?

I think you need to remove the then after the else.   [/list][/list][/list]
Title: Re: IF Else Statement on Parameter
Post by: et21 on 12 Jul 2022 06:28:04 PM
this is the error i keep getting:  Parsing error before or near position: 77 of: "case
when (?Parameter?) = 'Yes'
then [Data Item] ="
Title: Re: IF Else Statement on Parameter
Post by: bus_pass_man on 13 Jul 2022 05:24:42 AM

Also replace
then [Data Item] = 'Yes'
with
then 'Yes'
Title: Re: IF Else Statement on Parameter
Post by: BigChris on 13 Jul 2022 08:10:28 AM
Ok, it looks like you're trying to use that in a filter. Instead of
case
when (?Parameter?) = 'Yes'
then [Data Item] = 'Yes'
else then [Data Item]
end


You probably want something more like:
(?Parameter? = 'Yes' and [Data Item] = 'Yes') or [Data Item] <> 'Yes'
You might need to tweak the OR part to give you the data that you're looking for
Title: Re: IF Else Statement on Parameter
Post by: et21 on 13 Jul 2022 03:25:46 PM
Yes I tried to use if statement on the filter. is there any way I can use if statement on parameter in the filter section?