DrSammyD
DrSammyD

Reputation: 920

Unable to Sum formula in VS Crystal Reports

So I'm trying to sum a formula in visual studio crystal reports but only for the group level.

I have a one to many relationship of Contract to Ancillary_Charge. I'm trying to sum Contract.Cost, but also show each ancillary_charge. So I've set CONTRACT.ID as a group, and each ancillary charge as the detail.

The following is my formula for the ChargePrice

if ({@IsZero} or {@ShowPrice} = false) then 0 else {CONTRACT.CONTRACT_COST}

The formula for IsZero

({PAYMENT_TYPE.ID} = 1) and IsNull({CHARGE_STATUS.PAYMENT_STATUS});

The formula for ShowPrice figures out if it is at the group level and returns true or false

Global booleanvar thingy;
Global booleanvar otherthingy;

if (isNull({@Previous}) and thingy = false) then
  thingy := true
else
  thingy := false;

if otherthingy then
  thingy := true;
otherthingy := false;

if (isNull({@Previous}) = false and next({CONTRACT.ID})<>{CONTRACT.ID}) then
  otherthingy := true;

thingy

When I try to Sum ChargePrice, it tells me that "This field cannot be summarized".

Why? and else can I do what I'm trying to do, namely only add to the sum when

Upvotes: 0

Views: 1169

Answers (1)

vice
vice

Reputation: 605

Instead of getting crystal to do the summation, do it yourself.

Create two extra formulas

fmlReset

Global NumberVar Total;
Total:=0;

fmlDisplay

Global NumberVar Total;
Total

Change your chargeprice formula to

Global NumberVar Total;
if ({@IsZero} or {@ShowPrice} = false) then 
0;
else 
Total:=Total+{CONTRACT.CONTRACT_COST};

Place fmlReset in your page report header or whenever you want to reset your total. Place fmlDisplay where you want to display the total.

Upvotes: 1

Related Questions