COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: Cognos_Jan2017 on 25 Aug 2017 11:09:41 AM

Title: Calculation from "Total" Counts of 2 List Columns
Post by: Cognos_Jan2017 on 25 Aug 2017 11:09:41 AM
We have a simple Report utilizing Total Counts where those
two Columns appear in the underlying Query as ...
1 - Count(Action Item Status)   .... its value is 12
2 - Count(ClosedAfterDueDate) .... its value is 1

We can unlock one of the "unused" cells in the "Overall - Count" Row
to place a Data Item, and Lock that.

We should be able to write a Data Item to calculate the 1/12, but
an Expression Definition of ...
Count(ClosedAfterDueDate)/Count(Action Item Status)
... fails.

We need something like this ...
'Closed Percentage of '+Cast(1/12,varchar(50))
... where the 1 of Count(ClosedAfterDueDate), and the
12 of Count(Action Item Status) works in the Expression.

Is there a simple solution as we continue to learn more Cognos?

TIA, Bob
Title: Re: Calculation from "Total" Counts of 2 List Columns
Post by: Cognos_Jan2017 on 28 Aug 2017 11:05:28 AM
We have written a Query Calculation of ...
'Percent Closed After Due Date '+Cast(Count([ClosedAfterDueDate])/Count([Action Item Status]), varchar(50))+'%'
... that works fine.

That is placed in an "empty cell" (Locked/Unlocked) of the Calculated Totals Row of the List.
The only problem now is finding which varchar(x) value will, from ...
Percent Closed After Due Date 7.69230769230769E-2%
... display
Percent Closed After Due Date 7.69%

Will search for all varchar values.  Previous searches haven't found what's needed ... yet

Anyone know the correct varchar value to display a number w/ 0, 1, or 2 decimal places?

TIA, Bob
Title: Re: Calculation from "Total" Counts of 2 List Columns
Post by: Cognos_Jan2017 on 29 Aug 2017 12:51:43 PM
Could NOT get the attempted string concatenation to work.
Kept getting ...
Percent Closed After Due Date 7.69230769230769E-2%

Wound up Unlocking/ Locking an available empty cell in
the Totals/ Count row, adding a Block w/ 2 parts ...
a Data Item text of ...
Percent Closed After Due Date =
... followed by another Data Item of the calculated value
(formatted as Percent, 2 decimal places), of ... 7.69%.
Resulted in ...
Percent Closed After Due Date =7.69%

Looks good.  Would still like to string concatenate both
parts IF anyone finds a solution, please share.

Thank you, Bob
Title: Re: Calculation from "Total" Counts of 2 List Columns SOLUTION
Post by: Cognos_Jan2017 on 30 Aug 2017 10:50:33 AM
Got this from guy in my network ...

'Percentage Closed After Due Date = ' + cast(cast(Count([ClosedAfterDueDate])*100/Count([Action Item Status]),decimal(4,2)),varchar(5)) + '%'

But remember that having them as two items (the way you have it in your report right now) is efficient because two function calls to cast() will be reduced and hence less processing involved. But if it is not in many places in a report that you want to use this kind of recursive casting, then that shouldn't be much of a problem.