Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum of 2 formulas

Status
Not open for further replies.

ericb123

MIS
Mar 3, 2008
55
US
using CR11 & SQL2000:

I have a formula that counts errors in the db in a particular way:

whileprintingrecords;
numbervar A;
numbervar B;

// Audit error count for multiple errors
if {AuditTicketEntry.AuditErrorId} = [22] then
A := Count ({AuditTicketEntry.AuditErrorId},{AuditError.Description})

else
if {AuditTicketEntry.AuditErrorId} = [11] then
A := Count ({AuditTicketEntry.AuditErrorId},{AuditError.Description})

else

// Audit error count for one error
IF {AuditTicketEntry.AuditErrorId} = [5] and Count ({AuditTicketEntry.AuditErrorId},{AuditError.Description}) >= 1
then
B := 1
else

IF {AuditTicketEntry.AuditErrorId} = [9] and Count ({AuditTicketEntry.AuditErrorId},{AuditError.Description}) >= 1
then
B := 1

And then in my group footer, I have the following to get the sum:

whileprintingrecords;
numbervar A;
numbervar B;

B + A

But this is not working correctly, I'm trying to get the SUM of all the A's and all the B's in the footer, and it's only giving me what looks like the sum of the first 2. Any help is appreciated, thanks!

 
Please clarify the group structure of the report and where these formulas are located (in what sections). Please also show some sample data and the results you would expect to see.

-LB

 
Thanks for the reply. The data is grouped by user, the formulas are in the group headers, the detail is hidden. It's only in formulas because some error ID's, even if there are multiple errors are only supposed to count as 1 error for the user (numbervar B), the others can count multiple times (numbervar A). So it looks something like this:

User1 errors
error_type1 2
error_type2 1
error_type3 2
error_type4 2
error_type5 3
error_type6 2
Total: 12
User2 errors
error_type1 2
error_type2 1
error_type3 1
error_type4 2
error_type5 1
error_type6 2
Total: 9

The individual error type counts are my formula, and the total is supposed to be the sum of all the error counts in the group footer.

Thanks again!
 
All you need to do is change the description group level formulas so that the line that is setting the value is like this:

A := A + Count ({AuditTicketEntry.AuditErrorId},{AuditError.Description})

B := B + 1

Setting each value equal to itself plus some value is what allows the accumulation.

You do not need to change the report footer formula, but you will need a reset formula for the user group header:

whileprintingrecords;
numbervar A := 0;
numbervar B := 0;

-LB
 
Sorry, the report is actually grouped by USER (GH1), then by CLAIM_NUMBER (GH2), then by ERROR_TYPE (GH3). So, the formula I have for error count is accurate, if I allow it to accumulate, it adds the errors for error_type1 to error_type2. That's not correct.

But my total is in GF1, and I'm trying to sum all the counts in my formula in GH3.

Thanks again.
 
Okay, I didn't realize you were using the variable formulas to display in the Group #3 section. You should use my suggested method for accumulation, and suppress the accumulation formula. To display the values in the Group #3 formulas, create a separate formula:

if {AuditTicketEntry.AuditErrorId} in [11,22] then
Count ({AuditTicketEntry.AuditErrorId},{AuditError.Description}) else
if {AuditTicketEntry.AuditErrorId} in [5,9] and
Count ({AuditTicketEntry.AuditErrorId},{AuditError.Description}) >= 1 then 1

-LB
 
Thanks so much for the help, I really appreciate it. But I'm doing something wrong. How do I suppress just a formula?

I've got the formula that is supposed to accumulate in the group footer (GF3) and the formula that is supposed to add them all together in GF1, but the totals aren't adding up.

When I look at it, the totals are right, but if there's a record that doesn't meet the criteria, then it gets a count of zero, and if there's 2 zero's in a row, then it looks like it's adding 0 + 0, which is resetting the count.

Could this be? I think it might be my formula. Do I need to account for the possibility of a zero in it? Thanks!
 
You need to show the content of the formulas you are now using and identify in what sections they are placed. Also clarify whether you are suppressing any group sections which you don't want contributing to the count.

-LB
 
Thank you so much for your help, I got it to work fine. The final footer was resetting all my totals correctly, I just had to move the other totals up 1 section, and it's all fine. Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top