COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: V i n c e n t on 08 Dec 2010 06:50:27 AM

Title: Conditional count
Post by: V i n c e n t on 08 Dec 2010 06:50:27 AM
Hello all,

I need you help to for my problem.

My data : (for example)

CUSTOMERID  YEAR REVENUE
12310            2009   100
15666            2009   150
15666            2010   350
14899            2010   200
12324            2010   140
33467            2009   690
33467            2010   450
23423            2009    330
56464            2010    110

I need to count 3 things :
customer with revenue in 2009 but no revenue in 2010 (the result from example = 2)
customer with no revunue in 2009 but with revenue in 2010 (= 3)
customer with revenue in both year (= 2)

It's very hard to do that because it's like compare a null data with no null data.
I tried with count, count(distinct).. with no success.

Can someone help me ?

Thanks.

Title: Re: Conditional count
Post by: V i n c e n t on 09 Dec 2010 01:55:20 AM
No one to help me  ??
Title: Re: Conditional count
Post by: CognosPaul on 09 Dec 2010 03:47:08 AM
Excuse the brevity, not much time today.

Create a new query, drag in Customer ID.

Create a new data item called 2009 Revenue:
case when [NS].[Time].[Year] = 2009 then [NS].[Measures].[Revenue] else 0 end

Create a new data item called 2010 Revenue:
case when [NS].[Time].[Year] = 2010 then [NS].[Measures].[Revenue] else 0 end

Create a new data item called CountType1:
case when [2009 Revenue] > 0 and [2010 Revenue] = 0 then 1 else 0 end

Create a new data item called CountType2:
case when [2009 Revenue] = 0 and [2010 Revenue] = > then 1 else 0 end

Create a new data item called CountType3:
case when [2009 Revenue] > 0 and [2010 Revenue] > 0 then 1 else 0 end

Set the aggregations on everything but CustomerID to total.

Create a list based on this query with only the CountTypes.
Title: Re: Conditional count
Post by: V i n c e n t on 10 Dec 2010 08:55:37 AM
Thanks for your solution, i will try this.
Title: Re: Conditional count
Post by: V i n c e n t on 17 Dec 2010 02:53:09 AM
I try this but don't work.

Can you explain why i need customer ID if i dont use it in the list and in the data item ?
I need more explanations for the aggregation function.

Thanks.