Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Crystal Reports - Averages in report footer using WhilePrintingRecords

Posted on 2013-12-19
8
Medium Priority
?
1,444 Views
Last Modified: 2013-12-20
mlmcc helped me out a while ago with some code to calculate averages from running total forumulas in group footers.  Here's a solution I've been using:

http://www.experts-exchange.com/Database/Reporting_/Crystal_Reports/Q_28188490.html

It works great in group footers, but I was never able to get this to work with the report footer for grand total averaging.  What am I missing?



I added this formula to the report header:

WhilePrintingRecords;
Global NumberVar GrandTotal;
Global NumberVar Count;
Global NumberVar ReportGrandTotal;
Global NumberVar ReportCount;
""



I added the Report Grand Total variables to the formula doing the calculation of the total (GF4):

WhilePrintingRecords;
Global NumberVar GrandTotal;
Local NumberVar CurrentTotal;
Global NumberVar Count;
Global NumberVar ReportGrandTotal;
Global NumberVar ReportCount;

CurrentTotal := ({#Original Const - Close}-{#Original Const - Start})+1;

GrandTotal := GrandTotal + CurrentTotal;
Count := Count + 1;
ReportGrandTotal := ReportGrandTotal + CurrentTotal;
ReportCount:= ReportCount + 1;
CurrentTotal;



I added this formula to the report footer:

WhilePrintingRecords;
Global NumberVar ReportGrandTotal;
Global NumberVar ReportCount;
ReportGrandTotal / ReportCount
0
Comment
Question by:GStoner
  • 4
  • 3
8 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 39730541
Why do you think it isn't working?

mlmcc
0
 

Author Comment

by:GStoner
ID: 39730555
It's not returning an accurate value, so I assumed that I'm missing something or have a mistake in the formula.
0
 
LVL 3

Expert Comment

by:13Shadow
ID: 39730591
I am curious as to why you are using a formula to calculate average value. Is this a special average calculation?
If it is not, why not create a running total field with a type of average and let Crystal do the calculations for you?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:GStoner
ID: 39730942
The summaries in my group footers are formulas.  You cannot select a formula that resides in a group as the "Field to Summarize" for a running total.  I also cannot simply insert a summary by  selecting the formula #2 value in each group - again, you can't average formulas.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 39731059
You can average formulas provided they meet certain rules.

FOr instance the formula below can be used in summary functions including averages.

     {Field1} - {Field2}

The following can't even though it looks like the same formula.  It is evaluated in the rinting records pass which is after summary functions are evaluated.

WhilePrintingRecords;
     {Field1} - {Field2}

The formula he has above uses running totals for the calculations so you can't use it for summary functions since running totals are evaluated in the Printing Pass.

You say it is not accurate.  Can you give an example or upload the report with saved data?

mlmcc
0
 

Author Comment

by:GStoner
ID: 39731734
I've attached the report and also a pdf of the results.  The results in GF1 report correctly.
I want to average the GF1 averages in the report footer for company averages.

The one example I have in the RF returns 102.64, when it should be 104.09.


From a solution you provided on a similar report, I never was clear on lines 5 and 6.  
"Your formula 2" - Should I be including my formula on this line by itself?
"CurrentTotal := Your last line" - I never understood what Your last line was referring to.

As you can see in my report, I include my formula 2 in the CurrentTotal line as follows:
CurrentTotal := ({#Original Const - Close}-{#Original Const - Start})+1;

So maybe my version of the formula is not set up correctly.


Here's what you sent me in a different post.  See lines 5 and 6 versus how my formula is built.


You can modify your formula 2 to calculate the grand total
WhilePrintingRecords;
Global NumberVar GrandTotal;
Local NumberVar CurrentTotal;
Your formula 2

CurrentTotal := Your last line
GrandTotal := GrandTotal + CurrentTotal;
CurrentTotal

In the report footer add a formula to display the grand total
WhilePrintingRecords;
Global NumberVar GrandTotal;
GrandTotal
job-schedule-summary---bto-v3.pdf
Job-Schedule-Summary---BTO-v3.rpt
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 2000 total points
ID: 39731764
The average being calculated is correct.  Remember the average for the full report will almost never be the average of the averages.  

WHen you calculate the average of the averages you essentially assign equal weight to each group.  In your case the first group (BW) has only 2 rows but the other groups have 5 and 7 rows.

If you want the average of the averages then you need to do the addition with the average values rather than the individual values.

You modified your formula correctly.


mlmcc
0
 

Author Comment

by:GStoner
ID: 39731786
I should have known that.  When you stare at these reports too long, it's hard to think clearly.  Sorry for wasting your time - and thanks for your help.

<edited mlmcc>
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question