COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: seballen on 08 Mar 2012 12:14:54 PM

Title: Performing a calculation on a "Total" field from two separate queries?
Post by: seballen on 08 Mar 2012 12:14:54 PM
Hello Coggies,

Is it possible to perform a calculation on fields from two separate queries. Both fields are Totals (i.e. the Aggregate Function and the Rollup Aggregate Function are set to Total) and I need to calculate a percentage.

I can't generate both numbers in one query.

The report requires:

Dx: Total People With X Diagnosis
Poor Control: Total People With X Diagnosis who have not had Text Z or Results of Test Z are out of range

Percentage of People with X Diagnosis with Poor Control

Thanks,
Sasha
Title: Re: Performing a calculation on a "Total" field from two separate queries?
Post by: PRIT AMRIT on 08 Mar 2012 08:48:54 PM
For this you first have to establish a JOIN between these two queries based on a common column. Then create a calculated item and define your calculation(Percentage of People with X Diagnosis with Poor Control) on your final query.

Hope it helps.
Title: Re: Performing a calculation on a "Total" field from two separate queries?
Post by: seballen on 08 Mar 2012 09:04:36 PM
OK, so no way to just use the total values from un-joined queries in a calculation? Seems so strange that I can't just divide one total value by another...

I have many joins in this report and am hoping to speed it up.
Title: Re: Performing a calculation on a "Total" field from two separate queries?
Post by: barrysaab on 09 Mar 2012 03:34:05 AM
seballen,i think there is no other way out,you have to go with the join between these two queries.Thanks
Title: Re: Performing a calculation on a "Total" field from two separate queries?
Post by: Lynn on 09 Mar 2012 08:01:37 AM
You can union instead of join.

Both queries have a column for each metric, so the Dx query returns the Dx figure and the Poor Control figure is just a dummy expression that returns 0.

The Poor Control query does the opposite....it returns 0 for Dx and the actual poor control figure.

Then union those two queries and do the percentage calculation in the union result.
Title: Re: Performing a calculation on a "Total" field from two separate queries?
Post by: barrysaab on 11 Mar 2012 01:22:13 AM
Thanks,Lynn.Supposetwo queries are similar in datatype but one of them has one data item more item,in this scenerio we can't do uion but we left with only join option or we have any other options left.
Title: Re: Performing a calculation on a "Total" field from two separate queries?
Post by: cognostechie on 11 Mar 2012 02:49:49 PM
What Lynn said is that you can create a dummy data item with 0 value which will make the no. of data items same in both the queries so you can union them.