COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: knip on 09 Oct 2012 11:50:26 PM

Title: Running Subtraction
Post by: knip on 09 Oct 2012 11:50:26 PM
Hi All,
          I have a Total1 which is calculated at run time and Total2 which is also calculated at run time, can you please let me know how can i calculate Total2-Total1 at run time?
Title: Re: Running Subtraction
Post by: bvk.cognoise on 10 Oct 2012 01:37:48 AM
Hi Knip,

I am giving answer based on my undersstnading if i am wrong excuse me and please elaborate ur requiremnt.
if you had already calculated that running total for Total1 and Total2 ..then you can directly sustract thease two data items.
>go to query explorer
>click on your query
>then from tool box drag a data item into the query
> then clcik on data items tab drag  these two data item (total2 and total1)
  for eg:Total2-Total1
>then clcik on ok
it will give the result as u expected.

Regards
BVK
Title: Re: Running Subtraction
Post by: knip on 10 Oct 2012 02:15:49 AM
Hi BVK,
           Thanks for reply, but let me eloborate my requirement
   I have Total1 which is calulated at run time (this total is dependent on the case statement whcih i write and is calcuted), and similarly Total2 is dependent on the othe case statement,
Ex:
key col1 col2
1      I    100 
2      C    50
3      I     200

When i run my report on 1,2,3 my result is I-C 300-50=250 , running total i mean i have grouped by on certain key and summed the result at report level
Title: Re: Running Subtraction
Post by: pricter on 10 Oct 2012 02:49:29 AM
In my view you should create two queries
with the same data items
key col1 col2

and joined (outer join) them by using 

[query1][key]=[query2][key]-1
so on the query which is produced by the join you will have
key  col1    query1.col1        query2.col2         difference
1       I              100                         0                  100
2      C               50                       100                 -50
3      I               200                        50                -150