Save previous row value for current row in Crystal Report

I want to get the previous row value in the current row, as shown below (Crystal Report 2008):

+------------+-----------------+----------+------------+----------------+ | Date | PreviousBalance | Loan | Collection | CurrentBalance | +============+=================+==========+============+================| | 14/02/2012 | 00.00 | 10000.00 | 00.00 | 10,000.00 | | 15/02/2012 | 10,000.00 | 00.00 | 500.00 | 9,500.00 | | 16/02/2012 | 9,500.00 | 00.00 | 500.00 | 9,000.00 | | 18/02/2012 | 9,000.00 | 5,000.00 | 00.00 | 14,000.00 | +------------+-----------------+----------+------------+----------------+ 
+4
source share
7 answers

This is easier than it sounds:

  • Create two current {#TLoan} for Loan {#TLoan} for the {table.Loan} field and one for Collection {#TCol} for the {table.Collection} field.

  • Create a formula: {@Total} with the following contents:

{#TLoan}-{#TCol}

This will matter CurrentBalance.

  1. Create another formula: {@Prev} with the following contents:

{@Total}-{table.Loan}+{table.Collection}

This will matter PreviousBalance.

Using this approach, complex formulas are not needed, and the result will be expected.

enter image description here

enter image description here

Hope this helps!

+3
source

Using the previous() function seems like it would be an obvious choice for this solution, but since the formulas cannot refer to each other cyclically (ie {@CurrentBalance} cannot refer to {@PreviousBalance} versa), and they cannot be recursive, they are more difficult to implement it in such a way than it seems first.

Instead, you should use a variable to track the balance between transactions. You can do this by creating 3 formulas and placing them in the appropriate sections of your report.

 // {@initVars} - Initialize balance variable //This formula should be placed in your report header whileprintingrecords; numbervar balance:=0 // {@previousBalance} - Display previous line balance //This formula should be placed in your Details section whileprintingrecords; numbervar balance; // {@currentBalance} - Display current balance after transactions //This formula should be placed in your Details section evaluateafter({@previousBalance}); numbervar balance := balance + {table.LoanAmount} - {table.CollectionAmount} 
+2
source

I think there are several ways. What about:

previous({Table.Field})

Or can you have a total, and then {#total} - {Table.Field} ?

+1
source

In the stored procedure, save the previous balance inside the variable using a function that reads from the table and returns the previous balance and stores it inside the variable, and inside the stored procedure reads the current balance. Use union to read previous and current in split lines and get them in the report.

+1
source

Try:

 // {@PreviousBalance} If PreviousIsNull({@CurrentBalance}) Then 0 Else Previous({@CurrentBalance}) 
0
source

from a stored procedure (if you use it), order data by ASC date or if you do not use SP to sort the data table or data set by ASC date, then you need to define GROUPING criteria (ClientId) to group information for one client, for example, in orderings and groupings like you mentioned, you can group records from (Field Explorer β†’ Field Name Fields β†’ Insert Group)

0
source

look at the link. You did not specify a base data source, so I found a sample for MS SQL.

If you do not have access to the database to query / edit the stored procedure, you can write a foreach loop and calculate the corresponding values. The problem is that reports usually summarize, process, and filter data. The concepts of β€œprevious” and β€œnext” lose their meaning in this context.

0
source

All Articles