# Crystal Reports Question on initializing a value into a running total **Category:** [Vista/Vantage 8](https://www.epiusers.help/c/vantage-8/8) **Created:** 2016-11-17 19:37 UTC **Views:** 4532 **Replies:** 6 **URL:** https://www.epiusers.help/t/crystal-reports-question-on-initializing-a-value-into-a-running-total/36348 --- ## Post #1 by @jhenslee Trying to create a planning review report using a BAQ and Crystal Reports. I have the BAQ written but am having difficulty with the crystal report. One of the control breaks is on the part number. What I'd like to do is initial the running total field to the current quantity on hand and then as I go through records in the PARTDTL table, either add or subtract the PartDtl.Quantity to/from a rolling total (like) column and at the end of the records for that part be able to print the "projected" on hand balance - basically like what's on the time phase report - only I'm doing this because we have some warehouse sharing that's turned on and we want to exclude inventory in the shared warehouses so that we can determine when we'll need to re-order or create jobs to replenish inventory properly. I've been scouring the net for an hour and have not been able to find anything useful (yet). I'm sure someone out there has done something like this before? Thanks for any help! Jeff Henslee M-B Companies Inc. --- ## Post #2 by @josecgomez I haven't done Crystal Reports in eons but I think this approach would work Decalre a variable and assign the value of Qty On Hand (on Group Header Part) Then on each detail record use another formula field to subtract (InitialVariable - PartDtl.Qty) and assign it back to IntialVariable... Then at the end of the Part Group (Group Footer) Display your Initial Variable --- ## Post #3 by @josecgomez Something like This Formula Field One Global NumberVar QtyOH QtyOH := myField.QtyOnHand; Forumla Field Two (Details) (stick this on details make it font white and transparent so its not seen QtyOH := QtyOH - Part.Qty Formulae Field 3 QtyOH --- ## Post #4 by @jhenslee I’m closer – but still not working. I have the 3 formulas (shown below) Field1 Global NumberVar QtyOH :=({BAQReportResult.PartWhse.OnHandQty}); Field2 global Numbervar QtyOH := (QtyOH + {@TrxQuantity}); Field3 QtyOH TrxQuantity if {BAQReportResult.PartDtl.SourceFile} = "JH" then ({BAQReportResult.PartDtl.Quantity} * 1) else if {BAQReportResult.PartDtl.SourceFile} = "JM" then ({BAQReportResult.PartDtl.Quantity} * -1) else if {BAQReportResult.PartDtl.SourceFile} = "TO" then ({BAQReportResult.PartDtl.Quantity} * -1) else {BAQReportResult.PartDtl.Quantity} I’ve got something messed up – it’s not doing the running totals correctly. Here’s a snippet of my report. [cid:image001.jpg@01D24FA1.F89EEEA0] I’m close (ok – maybe not that close) – but the first line works – it’s just every line after that! Thanks. Jeff --- ## Post #5 by @EpiUser whenever I've done the three formula trick I have the first formula just resetting the variable to zero. So the first formula resets the variable on the group you are resetting the running total on. If this is a grand total this formula is not really needed as you are summing on the entire data set. The second formula is your running total, this is where you are doing your calculation for ever detail line, or child group header/footer. the last formula just displays the results of the second calculating formula. So perhaps assigning the variable in formula one is your issue? Field1 ==> in the group header Global NumberVar QtyOH :=0; Field2 ==> in the detail portion where your rows are you are wanting to total global Numbervar QtyOH := (QtyOH + {@TrxQuantity}); Field3 ==> in the area where you want to display the total before resetting. usually for me the group footer. QtyOH TrxQuantity if {BAQReportResult.PartDtl.SourceFile} = "JH" then ({BAQReportResult.PartDtl.Quantity} * 1) else if {BAQReportResult.PartDtl.SourceFile} = "JM" then ({BAQReportResult.PartDtl.Quantity} * -1) else if {BAQReportResult.PartDtl.SourceFile} = "TO" then ({BAQReportResult.PartDtl.Quantity} * -1) else {BAQReportResult.PartDtl.Quantity} --- ## Post #6 by @litzer67 It has been awhile since doing Crystal In the Group Header that correlates with the Group Footer your showing the total WhilePrintingRecords; NumberVar QtyOH := 0; At the point in which you want to do the running total WhilePrintingRecords; NumberVar QtyOH := (QtyOH + {@TrxQuantity}); In the Group Footer where you want to show the total WhilePrintingRecords; NumberVar QtyOH; Scott --- ## Post #7 by @jhenslee Thanks for the help! I was (finally) able to doget running totals on a crystal report to work - basically initializing the working field with the OH quantity from the warehouse and then adding it to the running total field. It was a combination of a couple of suggestions and the use of running total and calculation fields. It's working now. Thanks again! --- **Canonical:** https://www.epiusers.help/t/crystal-reports-question-on-initializing-a-value-into-a-running-total/36348 **Original content:** https://www.epiusers.help/t/crystal-reports-question-on-initializing-a-value-into-a-running-total/36348