COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: hemantsoni on 01 Jun 2012 08:20:17 AM

Title: Count a particular field with few conditions.
Post by: hemantsoni on 01 Jun 2012 08:20:17 AM
Hi Gurus,
I have a list report which contains Clientcode, Certno, Policy no,Prodcode,Status etc.
However I want to count the status where status ='T' for every change of ProdCode.

Can anyone Pls tell me how to achieve this?

Thanks a lot in advance!!!
Title: Re: Count a particular field with few conditions.
Post by: Lynn on 01 Jun 2012 09:29:15 AM
You can try to create a query item with an expression that is either T or null depending on the status and set the aggregation to count. Nulls are not counted. Or you could use 1 and 0 and set the aggregation to sum which might achieve the same result.


case [Status] when 'T' then [Status] else null end


or you can try an explicit count function


count(case [Status] when 'T' then [Status] else null end for [Clientcode], [Certno], [Policy no], [ProdCode])

Title: Re: Count a particular field with few conditions.
Post by: blom0344 on 01 Jun 2012 09:30:07 AM
Quote from: hemantsoni on 01 Jun 2012 08:20:17 AM
..... for every change of ProdCode.

What do you mean by that? Change in the list as displayed going from top to bottom?
Title: Re: Count a particular field with few conditions.
Post by: hemantsoni on 01 Jun 2012 09:44:03 AM

Gurus,
Thanks for your quick response.
status =T is ok.But what about prodcode??
For every change of prodcode means it should show the count of statuses where status ='T' for each prodcode.

In a SQL Clause it should be grouped by prodcode.
Title: Re: Count a particular field with few conditions.
Post by: wyconian on 18 Jun 2012 11:08:48 AM
Hi

I would use Lynn's suggestion of a case statement returning 1 or 0 where the status is T (call this T_COUNT) then group your query on prodcode and do a total(T_COUNT for prodcode).

That should give you a count of items where the status = T for each change in prodcode.

Good luck :-)