# Crystal Reports - Need the sum of a formula that uses 'previous' function

I have a formula named @G Qty.
The formula is:
if (({Glovia_.LOC BIN LOT} = previous ({Glovia_.LOC BIN LOT}) and {@Item Number} = previous ({@Item Number})))
then 0
else {Glovia_.Qty}
I need the sum of this formula at each change in the group 'Item Number'.
I have read examples of how to do this with whilereadingrecords but all it has done is confuse me.
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
You do this with 3 formulas

The first formula declares and initializes the variables required
The second formula does the addition/summary
The third formula displays the value

Formula 1 - DeclareVariables
``````WhilePrintingRecords;
Global NumberVar TotalQty;
TotalQty := 0;
''
``````

Formula 2 - SumQty
``````WhilePrintingRecords;
Global NumberVar TotalQty;
if (({Glovia_.LOC BIN LOT} = previous ({Glovia_.LOC BIN LOT}) and {@Item Number} = previous ({@Item Number})))  then
0
else
TotalQty  := TotalQty  + {Glovia_.Qty};
''
``````

Formula 3 - DisplayTotal

``````WhilePrintingRecords;
Global NumberVar TotalQty;
TotalQty
``````

Formula 2 goes in the detail section
Formula 3 goes in the Group footer

mlmcc

Experts Exchange Solution brought to you by