Maximum and Minimum values from a summed Formula in Crystal Reports 2008

倾然丶 夕夏残阳落幕 提交于 2020-01-06 13:29:16

问题


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.



来源:https://stackoverflow.com/questions/22985887/maximum-and-minimum-values-from-a-summed-formula-in-crystal-reports-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!