Conditional Running Total in Crystal Reports

crystal-reportscumulative-sum

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 field BillableHours. At change of group, I am comparing GroupRunningTotal to a db field for that group MaxHours, and I display a result of MaxHours - 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.

Best Answer

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:

  1. 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.

  2. 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.

  3. Insert both running totals in the group footer (if you put them in the header, it may not sum properly)

Alternatively, you can:

  1. 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.

Related Topic