开发者

crystal report use Maximum as Sum condition problem

I met a problem with sum function: the data have a datetime column and I want to get sum of who's datetime is max. And also there's anoher group condition. So I do like:

  1. Add form开发者_StackOverflow中文版ula maxDatetime: Maximum({datetime}, {groupcondition})
  2. Add new formula for sum ValueToSum: if({datetime} = {@maxDatetime}) then value else 0
  3. Sum the value, add new formula totalValue: Sum({@valueToSum}, {groupcondition})

The result is the sum can't be processed, it says: 'valueToSum can't be sumed'.

I think the causor may be using a maximum value as a condition in step 2. Because when use 1 = 1 to replace the condition, there's no problem.

Can anyone give some advice?


We usually solve such kind of problems by creating additional queries and linking them to main data. Because Crystal Reports does only two passes over data - record reading and aggregate calculation, it can't easily aggregate over already aggregated values.

Another possibility is to accumulate your 'totalvalue' into variable. Something like next may work (needs tweaking probably):

WhilePrintingRecords();
NumberVar totalvalue;
If ({datetime} = Maximum({datetime}, {groupcondition})) 
then totalvalue:=totalvalue+value 
else 0

This formula (which displays totalvalue) needs to placed into group footer:

WhilePrintingRecords();
NumberVar totalvalue

Somewhere in group header you need another one to reset totalvalue:

WhilePrintingRecords();
NumberVar totalvalue:=0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜