Maximum and Minimum values from a summed Formula i

2019-09-07 03:50发布

问题:

Maximum and Minimum values from a summed Formula problem

Hello, I am currently using Crystal Reports 2008 which is getting its data from an Oracle database. I have looked into this at length and I have been unable to find the information I need. I have query about getting the Maximum and Minimum values from a given formula which totals 2 or more fields. A snapshot of the information I am using is:

Field1 = dB1.Left_Serious
Field2 = dB1.Left_Dangerous
Field3 = @Tester
Formula = @LeftTot

Fields 1+2 are the total score given by the Tester for each Left Test.

Test   Field1   Field2   Field3
1      2.0      4.0      J Adams
2      1.0      1.0      J Adams
3      1.0      0.0      S Grey
4      0.0      1.0      S Grey
5      5.0      0.0      D Jones
6      5.0      8.0      D Jones

The formula to get the Grand Total for each Tester’s Left Test uses a grouping by Tester:

@LeftTot  
Sum ({dB1.Left_Serious}, {@Tester}) + Sum (dB1.Left_Dangerous}, {@Tester})

Using the above details we get:

J Adams = 8.0 
S Grey = 2.0 
D Jones = 18.0 

The Maximum figure is therefore 18.0 and the minimum figure is 2.0 and the required difference is 16.0.

The problem I have is I cannot use the Maximum or Minimum commands as Crystal 2008 will not let you use the Summary Functions like Maximum on a formula that sums two fields. I know you could create a new aggregate field in the database which would solve the problem however I currently do not have administrator access to the databases and cannot create any new data tables or fields.

I have tried to get the ball rolling by using the following code in 3 new formulas:

@LeftTotGrpHdr
//This Formula needs to be placed into the Group Header to reset variable
WhilePrintingRecords;
NumberVar LEFTTL:=0

@LeftTotGrpFtr
//This Formula needs to be placed into the Group Footer to display variable
WhilePrintingRecords;
NumberVar LEFTTL

@LeftTotCr
//This Formula declares and works out Total Left Tests 
WhilePrintingRecords;
Global NumberVar LEFTTL:=LEFTTL + {@LeftTot}

However when I try to use

Maximum({@LeftTotCr})

in a new formula I still get the error message “This field cannot be summarised.”

Is there another way to do this?

Cheers

Daveyt

回答1:

There is a workaround for this.

When you summarize the value at the same time store the values in array and retrive maximum and minimum from the array.

    //@LeftTot  
    Shared StringVar Array x;

    x:=x+totext(Sum ({dB1.Left_Serious}, {@Tester}) + Sum (dB1.Left_Dangerous}, {@Tester}));
1

Now create one more formula @display

EvaluateAfter(@LeftTotal);
Whileprintingrecords;
Shared StringVar Array x;

Maximum(x);

In the same way do for minimum using the minimum function.

Let me know how it goes.