I'm relatively fresh to Cognos Reporting but this particular issue I can see arising in any technology stack. We were dealing with 'lifecycle' data so that customers go through a number of lifecycle stages. So for instance, they:
- request a product
- are approved for a product
- receive the product
or..
- request a product
- get turned down for a product
or even...
- request a product
- are approved for a product
- receive the product
- Cancel the product
And for each of these stages, you will know the date on which that stage was reached. You end up in a potential state of confusion with this kind of data as the users may request metrics such as:
- How many customers were approved in March?
- How many customers were waiting for approval at the end of March?
With this kind of time series data the understanding can be subtle and users (and developers) can easily get confused. Of course, it depends on the definitions provided but generally for:
a) Customers approved in March
you would count the number of 'Approved' events that occurred in the month of March - relatively easy. The SQL would be straightforward and your report would just have a single Date Range Calendar widget.
SELECT COUNT(*)
FROM tFACT
WHERE Stage = 'Approved'
AND EffectiveFromDate BETWEEN '01-MAR-2012' AND '31-MAR-2012'
b) Customers were waiting for approval at the end of March
This is trickier, as you potentially have some weird cases such as where the Customer has been waiting for approval since February and has no activity in March. Having a Date Range calendar widget here wouldn't work as it wouldn't pick up these cases.
In such cases you need to consider ALL data up to the end of March and (not only that) work out what the last event was. This is, of course, not the same as the current event assigned to the Customer as lots of other events could have happened since then.,
To do this you need to use Ranking functions within Cognos. Within the Query Explorer, for your main query add an additional Data Item with an appropriate name such as 'Data Rank'. Then use the Expression Definitions as follows:
rank ([Effective From Date] DESC FOR [Customer ID])
then within the Detail filters set:
[Data Rank] = 1
[LifeCycle Stage] = 'Approved'
[Effective From Date] < pReviewDate
where pReviewDate comes from a single entry Calendar widget.
One gotcha is that the Ranking has to be done before the filters are applied. I managed to fix this by setting
Application = Before Auto Aggregation
on the [Data Rank] filter.
This worked a treat and I extended the report so that I could input the Lifecycle Stage I was interested in. This meant I could drive the report and make it show me all the Customers at a given Stage at any moment in time.
The next stage would be count how many had reached a certain stage Cheers.