COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: madhancog on 31 Jul 2011 11:32:02 AM

Title: previous values in relational report
Post by: madhancog on 31 Jul 2011 11:32:02 AM
Hi gurus,
  Let me know how to get previous values in relational reporting.
  order number  prev oredernumber
     1002                 --
     1005                1002
     1006                1005

let me know how can i get the prev value in relational model.

Thanks in advance
K.M
Title: Re: previous values in relational report
Post by: Lynn on 01 Aug 2011 08:57:51 AM
I don't know how your data is structured, but you might try using the running-count function. Then join the query to itself.

Create your base data query to return:

Order OrderCount PrevCount
1002     1               0
1005     2               1
1006     3               2


Create the OrderCount item by using the expression running-count(1). You may need to provide scope via the "for" clause.

Create the PrevCount item by using the expression [OrderCount] - 1.

Now create your previous query. This is just a query reference back to base data query and drag in [Order] and [OrderCount].

Finally, create your report query as an outer join between the base data query and the previous query. Join [PrevCount] from base data query as 1..1 to [OrderCount] in previous query as 0..1.

Drag the desired elements from the two queries into the report query and associate your layout to this query.

This will require a lot of local processing so for very large data volumes it may not be practical. If this is the case you may want to investigate database options so that the previous order number is available directly.