There are several ways to do a running total. Your options on which to use depend on your Seagate Crystal Reports (SCR) version number, and database type.
1) The easiest is to use the Insert|Running Total wizard. This is not always accurate in SCR v7 and below. Easy, but use at your own risk.
2) Use the three formula approach.
This is reliable, but more time consuming to write.
In this example, the running total calculates the number of employees in a dept.
//goes in group header for dept, resets count to zero
WhilePrintingRecords ;
NumberVar DeptEmpCount := 0
//goes in the detail section, increments employee count
WhilePrintingRecords ;
NumberVar DeptEmpCount := DeptEmpCount + 1
//goes in the group footer for dept, shows dept emp count
WhilePrintingRecords ;
NumberVar DeptEmpCount
3) Lastly, writing the RT in SQL will give you the best performance, but requires some experience with SQL. These running totals examples are for a bank account, where the running total is the balance of the account after each transaction.
SELECT B0.transaction, B0.transdate, SUM(B1.amount) AS balance
FROM BankAccount AS B0, BankAccount AS B1
WHERE B1.transdate <= B0.transdate
or using a scalar subquery (great terminology to confuse and intimidate)
SELECT B0.transaction, B0.transdate,
(SELECT SUM(B1.amount)
FROM BankAccount AS B1
WHERE B1.transdate <= B0.transdate) AS balance
FROM BankAccount AS B0
Crystal gurus will note that both of these SQL solutions require modification of the SELECT portion of the SQL statement, which isn't permitted in Crystal Reports. Thus, you will have to use a view, stored procedure, temporary table, or the SQL Query tool to circumvent this limitation.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.