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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a summary field 1

Status
Not open for further replies.

JCruz063

Programmer
Feb 21, 2003
716
US
I have a report that has some summary fields - the sum of some other fields within the same report. Instead of displaying the value of the summary fields, I would like to display their values divided by 3. What I have in mind is that I have to use perhaps a formula field and access the summary field in the formula field and divide by three, like this:
Code:
[COLOR=green]// This is Crystal syntax[/color]
[COLOR=blue]whileprintingrecords[/color];
[COLOR=blue]numberVar[/color] ans;
ans = {@MySummaryField}/3
This code, however is not giving me the right result. Does anybody know what I'm doing wrong?

Thanks!

JC

 
You are missing the colon:

whileprintingrecords;
numberVar ans;
ans := {@MySummaryField}/3

-LB
 
Hard to say since you didn't share what's in {@MySummaryField}

Also it's useful to post other basic technical inofrmation, such as:

Crystal version
Database used
Example data
Expected Output

And to simplify your formula, don't use variables when they aren't required, just use:

{@MySummaryField}/3

or use

({table.field1}+{table.field2}+{table.field3})/3

-k
 
Thanks guys!

lbass,
That's not the case since my formula doesn't look the way I posted it before. I posted it that way so that it would be easliy readable. The way it really looks is this:
Code:
[COLOR=blue]whileprintingrecords[/color];
{@Job1Count}/3;
synapsevampire,
Here's the deal. What I have is a formula called @Job1Count that counts the number of certain items in the database. The text of @Job1Count is as follows:
Code:
[COLOR=blue]if[/color] {MyTable.JobNumber} = 1 [COLOR=blue]then[/color]
   1
[COLOR=blue]else[/color]
   0
This formula is in the details section (which is suppressed) and it simply returns 1 for all records where the JobNumber field is 1.

Note: The details section of my report is suppresed and I display the data using the headers/footers of groups in the report.

In a group footer, I have a summary field which is the Sum of the @Job1Count formula. So, when the report prints, this summary field (the sum of @Job1Count) will display, let's say, 450 and that would be the total number of records in the database where JobNumber is 1. That 450, though, is distributed in x number of days (let's say 3) and what the user wants to see is the average of Job1Count in those 3 days. Thus, instead of displaying 450, I need to display 450/3 = 150.0 which would be the average number of Job1 occurances in each day. Using an Average summary instead of a Sum does not work because the average is computed as TotalSum/NumberOfRecords. This, as you may already know, does not make sense here because the average I want is TotalCount/NumberOfDays, and thus I have to compute the average manually. So, I need a way to access the Sum of @Job1Count so that I could divide it by the number of days and show it to the user. How can I access the total sum of @Job1Count?

Here's some info about my environment.
I'm using Crystal Reports 10 Developer Edition, reporting of a SQL Server 2000 database.

Thanks again!

JC

 
Try:

sum({@job1count})/3

Or, if you want to check for the number of days corresponding to the conditional count, you could create a running total {#dates} and select {table.date}, distinctcount, evaluate using a formula:

{MyTable.JobNumber} = 1

Reset never.

And then change the formula to:

sum({@job1count})/{#dates}

This would be displayed in the report footer.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top