COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: et21 on 19 Jul 2022 05:47:16 PM

Title: count
Post by: et21 on 19 Jul 2022 05:47:16 PM
Hi all can someone please point out what's wrong with my count here? below is what my expression is and below that is the error.

case when ([Presentation].[Risk Register].[Status] = 'Open')
then ((count([Presentation].[Risk Register].[Risk ID] for [Presentation].[Projects].[Project Name]))
else ('0')
end

Incompatible data types in case statement

Title: Re: count
Post by: bus_pass_man on 20 Jul 2022 06:54:28 AM
The error message is complaining that there's incompatible data types. 

You are creating a numeric data type with the count and creating a string with the '0'.
Title: Re: count
Post by: MFGF on 20 Jul 2022 06:56:55 AM
Quote from: et21 on 19 Jul 2022 05:47:16 PM
Hi all can someone please point out what's wrong with my count here? below is what my expression is and below that is the error.

case when ([Presentation].[Risk Register].[Status] = 'Open')
then ((count([Presentation].[Risk Register].[Risk ID] for [Presentation].[Projects].[Project Name]))
else ('0')
end

Incompatible data types in case statement

Hi,

This expression is returning a numeric value for the 'then' clause and a character value for the 'else' clause. You need to return values of the same data types. One option is to remove the single quotes from around the '0' in the 'else' clause so that both clauses return numeric values. The other option is to cast the count from the 'then' clause to a char or varchar value so that both clauses return character values.

Cheers!

MF.
Title: Re: count
Post by: cognostechie on 28 Jul 2022 03:12:55 PM
This always works for me:

count (distinct
    case when (   )
    then (  )
)

No need for else