多个汇总值的最大值

时间:2014-11-07 03:06:46

标签: crystal-reports

我很难从组部分中的多个汇总值中获取maxiumu值。例如,我在报告组部分汇总了预算,承诺,成本和预测总计,现在在组页脚中,我需要选择四个总计的最大值。我该怎么办?

编辑.............................................. ..............

1) Sum ({@Total Contracted Value}, {JCM_MASTER__COST_CODE.Cost_Code}), 
2) Sum ({@Current Budget}, {JCM_MASTER__COST_CODE.Cost_Code}) 
3) Sum ({@Costs to Date}, {JCM_MASTER__COST_CODE.Cost_Code}) 
4) Sum ({@Projected Final PM Input}, {JCM_MASTER__COST_CODE.Cost_Code}) 

我需要在组页脚部分的四个总计中找到最高值

2 个答案:

答案 0 :(得分:0)

您需要为变量初始化的第1个创建两个公式字段,为值大于其他的条件创建第2个公式字段。

1:创建第一个公式字段并记下以下代码。将该公式字段的名称指定给Initialization

WhilePrintingRecords;
numbervar dMax := 0;

然后将该公式字段放在“报告标题”部分中。

2:现在,创建另一个公式字段并在该公式字段中记下以下代码。

WhilePrintingRecords;
//dont initialize the 0 in this variable we have already initialized in 1st formula field
numbervar dMax; 

//Following condition will check that current sum of that field is greater than 
//values stored dMax variable. If the condition is satisfied then value will be initialized
//In dMax variable.
if (IsNull(Sum({TableName.FieldName}, {TableName.GroupField})) = False AND 
     Sum({TableName.FieldName}, {TableName.GroupField}) > dMax)
    dMax:=Sum({TableName.FieldName}, {TableName.GroupField}); 

dMax;

现在,将此公式字段放在计算汇总值的位置。例如在组页脚中。

<强>更新

如果你想找出四组总数的最大值。然后在公式字段中记下以下代码并将其放在组页脚中。

WhilePrintingRecords;
numbervar dMax1:=0;
if (Sum ({@Total Contracted Value}, {JCM_MASTER__COST_CODE.Cost_Code})) > (Sum ({@Current Budget}, {JCM_MASTER__COST_CODE.Cost_Code}))
     dMax1:=Sum ({@Total Contracted Value}, {JCM_MASTER__COST_CODE.Cost_Code});
else
     dMax1:=Sum ({@Current Budget}, {JCM_MASTER__COST_CODE.Cost_Code});


numbervar dMax2:=0;
if (Sum ({@Costs to Date}, {JCM_MASTER__COST_CODE.Cost_Code}) ) > (Sum ({@Projected Final PM Input}, {JCM_MASTER__COST_CODE.Cost_Code}))
     dMax2:=Sum ({@Costs to Date}, {JCM_MASTER__COST_CODE.Cost_Code});
else
     dMax2:=Sum ({@Projected Final PM Input}, {JCM_MASTER__COST_CODE.Cost_Code});

if (dMax1 < dMax2)
    dMax1 := dMax2;

dMax1;

答案 1 :(得分:0)

尝试使用数组......

将所有值存储在数组中,并在组页脚中存储数组的最大值。

当您汇总该值时,同时将值存储在数组中并从数组中追溯最大值。在组

中的汇总数据之后放置下面的公式
//@Storedatainarray  
Shared StringVar Array x;

x:=x+totext(Sum ({field}, {@group}));

现在再创建一个公式@display

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

Maximum(x);

让我知道它是怎么回事?

编辑....................................

创建公式@Display并在group footer中写下代码:

Shared StringVar Array x;

    x[1]:= Sum ({@Total Contracted Value}, {JCM_MASTER__COST_CODE.Cost_Code});
    x[2]:= Sum ({@Current Budget}, {JCM_MASTER__COST_CODE.Cost_Code});
    x[3]:= Sum ({@Costs to Date}, {JCM_MASTER__COST_CODE.Cost_Code});
    x[4]:= Sum ({@Projected Final PM Input}, {JCM_MASTER__COST_CODE.Cost_Code});
Maximum(x);