Normal Topic Using Sums in calculations (Read 846 times)
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Using Sums in calculations
Jul 3rd, 2013 at 12:51pm
Print Post Print Post  
I have a basic report that includes several columns of numbers.  The report has two summary calculation elements that are the sum of each column.  I want to divide the sum of one column by the sum of another column but when I create an unbounded number element and try to create the calculation, I get an error stating "Operation is not defined for the types of the operands".

My programming is very simple:


// calculate the total reject percentage      

     TTLRejectPercent=(SumRejQty/SumTTLPcs)*100


I've verified all three elements are numbers.

Is it possible to use Summary Calculation elements in other calculations?  All three elements are in the Group Footer 1 section of the report.

  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Using Sums in calculations
Reply #1 - Jul 3rd, 2013 at 9:27pm
Print Post Print Post  
You need to move TTLRejectPercent to a row after (below) Group Footer 1. This can be in another View section (after the current one), or it can simply be a matter of moving it to the footer of the current view (labeled "View Footer").

You will also need to put the values from SumRejQty and SumTTLPcs into static variables.

Here's what you need to include in your programming...

Code
Select All
In the Global Code event:
stat sSumRejQty as Double
stat sSumTTLPcs as Double

In the TTLRejectPercent :: On Print event:
sSumRejQty = SumRejQty
sSumTTLPcs = SumTTLPcs

If sSumTTLPcs <> 0
	TTLRejectPercent=(sSumRejQty/sSumTTLPcs)*100 



The conditional checking if sSumTTLPcs <> 0 prevents a possible "Division by Zero" error.

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: Using Sums in calculations
Reply #2 - Jul 9th, 2013 at 9:25pm
Print Post Print Post  
I tried your suggestion and it works fine. 

Thanks for the help.
  
Back to top
 
IP Logged