Search code examples
crystal-reportscrystal-reports-2010

Cystal Report Accumulated Balance First Record Missing


enter image description here

I have used the following formula in the UnboundNumber (Accumulated balance), but the blue circled field is missing and wrong coming:

If Next({SP_Aging;1.AHead}) = Previous ({SP_Aging;1.AHead}) Then 
  numberVar X := (X +  {SP_Aging;1.Balance} )

Else
  X := 0 +{SP_Aging;1.Balance}

;

Solution

  • Try:

    // {@Accumulated Balance}
    
    // declare variable; mark as `global` to be explicit (w/o this, the variable is `global`, but this makes it clearer)
    Global Numbervar balance;
    
    // if this is the first row, increment the balance; always test for NULL values first in CR
    If PreviousIsNull({SP_Aging;1.AHead}) Then
    
      balance := {SP_Aging;1.Balance}
    
    // if the current row's AHead is the same as previous row's value, increment balance
    Else If {SP_Aging;1.AHead} = Previous({SP_Aging;1.AHead}) Then 
    
      balance := balance + {SP_Aging;1.Balance}
    
    // otherwise, reset
    Else
    
      balance := {SP_Aging;1.Balance}