Conditional Running Total in Crystal Reports
Solution 1
You most likely cannot use one RT field as condition for other RT field. You can use formulas, placed on group footer and evaluated 'whileprintingrecords()'; in these formulas you can assign/sum into some variables and display these variables at the end of report. About like next (generic idea only, you need initialization and display routines as well):
numbervar rtcurrent := sum({somefield}, {groupfield});
numbervar rtplus;
numbervar rtminus;
if (rtcurrent > 0)
then rtplus := rtplus + rtcurrent
else rtminus := rtminus + rtcurrent;
Solution 2
I'm interpreting your question to mean that you want to add up all the negative values in one running total (RT_Neg) and all the positive values in another (RT_Pos). How about this:
Make the RT_Neg running total. Under Field to Summarize, sum your {Tbl1}.{Amount}. Under evaluate, enter "{Tbl1}.{Amount}<0" as your custom formula. Never reset.
Make the RT_Pos running total. Under Field to Summarize, sum your {Tbl1}.{Amount}. Under evaluate, enter "{Tbl1}.{Amount}>0" as your custom formula. Never reset.
Insert both running totals in the group footer (if you put them in the header, it may not sum properly)
Alternatively, you can:
- Make a custom formula "If {Tbl1}.{Amount}<0 then {Tbl1}.{Amount} else 0" and make a running total based off that.
I think one of these 2 options will get you to your goal.
Lill Lansey
I'm the web developer at work. I do everything from asking the users the right questions to creating the UI to setting up the SqlServer backend. What technology will I learn today?
Updated on November 14, 2020Comments
-
Lill Lansey over 3 years
Using VS 2008 Crystal Reports, I would like to do a running total on a formula that is calculated on a group change. When I click on add a running total, this formula does not appear in the Available Tables and Fields list.
This is the logic:
On Change Group of group
if CalculatedValue > 0 then ReportRunningTotal1 += CalculatedValue else ReportRunningTotal2 += CalculatedValue
Can I specify a condition in a running total? If not, how else could I do this?
More info: I am doing a running total called
GroupRunningTotal
of the value of db fieldBillableHours
. At change of group, I am comparingGroupRunningTotal
to a db field for that groupMaxHours
, and I display a result ofMaxHours - GroupRunningTotal
at the group level.Appropriate today - Think of it like the electoral college - the person who wins the election does not depend on total number of votes, but of number of votes in the electoral college.