cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with using formula in running total

Former Member
0 Kudos

I'm using Crystal Reports v10 and I'm running into an issue with using formulas in a running total. I've done this same procedure in a previous report and the report allowed it which is why I can't understand why it won't work now.

The report starts off with 5 formulas with 4 being calculated off the first formula.

The first formula is called currWarrBaseYrPrc and it contains the following code:

currencyVar warrBaseYrPrc := 0;

if ((not isnull({VI_PS_TKT_HIST_LIN.PRC_1}) and {VI_PS_TKT_HIST_LIN.PRC_1} = 0 or isnull({VI_PS_TKT_HIST_LIN.PRC_1})) and not isnull({VI_PS_TKT_HIST_LIN.PRC})) then

    warrBaseYrPrc := {VI_PS_TKT_HIST_LIN.PRC} * {@Warranty%} * {VI_PS_TKT_HIST_LIN.QTY_SOLD}

else if (not isnull({VI_PS_TKT_HIST_LIN.PRC_1}) and {VI_PS_TKT_HIST_LIN.PRC_1} <> 0) then

    warrBaseYrPrc := {VI_PS_TKT_HIST_LIN.PRC_1} * {@Warranty%} * {VI_PS_TKT_HIST_LIN.QTY_SOLD}

else

    warrBaseYrPrc := 0;

warrBaseYrPrc;

The other formulas are calculated based off this formula as shown below:

currWarr2YrPrc:

currencyVar warrBaseYrPrc;

if ({@IsYear1Included?}) then

    warrBaseYrPrc * {@Warranty%Increase}

else

    warrBaseYrPrc;

currWarr3YrPrc:

{@currWarr2YrPrc} * ({@Warranty%Increase});

currWarr4YrPrc:

{@currWarr3YrPrc} * ({@Warranty%Increase});

currWarr5YrPrc:


{@currWarr4YrPrc} * ({@Warranty%Increase});

@Warranty% and @Warranty%Increase are calculated based on parameters as shown:

Warranty%

{?Warranty %} / 100.0

Warranty%Increase

(1 + {?Warranty % Increase} / 100.0)

@IsYear1Included?

if ({?Year 1 Included?} = false) then

    true

else

    false

All these formulas are in the same two sections of the report Group Header 2c and 2d. I want to do a running total on each of the "Warr" formulas in Group Footer 1f but, for some reason, I can only put @currWarrBaseYrPrc in a running total and all the other ones aren't accessible for the field to summarize.

I'm not sure why because I implemented this design before in a different report with no parameters without issue. Can someone identify what I'm doing wrong?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Jacob,

Is there a "whileprintingrecords;" in the currWarr2YrPrc formula?

Former Member
0 Kudos

No, there isn't. But I think I might have figured it out. When I place evaluateafter (@currWarrBaseYrPrc) in the @currWarr2YrPrc, it allowed me to use @currWarr2YrPrc in the running total. There seemed to be an issue with trying to figure out the order in which to evaluate @currWarrBaseYrPrc and @currWarr2YrPrc. I didn't want to push the formula evaluation to the whileprintingrecords pass because you can't doing running totals on formulas with whileprintingrecords because running totals are evaluated in the whileprintingrecords pass and can only use first pass data.

Former Member
0 Kudos

Hah I know you cannot pass a whileprintingrecords formula into a Running Total, which is precisely why I asked .

The reason why the formula did not show up on the Running Total Field is due to the fact that it had a 0 value for all of the lines.

Without the evaluateafter function, your global parameter would not have passed from currWarrBaseYrPrc into currWarr2YrPrc


In actuality your formula would have been evaluated as so for all of the lines.

currencyVar warrBaseYrPrc;

if ({@IsYear1Included?}) then

    0 * {@Warranty%Increase}

else

    0;

However, since you added the evaluateafter function, the global parameter "warrBaseYrPrc" was able to pass from one formula to the other.

Nifty! I didn't know you can pass parameters between formulas w/ the evaulateafter function.

Former Member
0 Kudos

Well, I guess my thought process was declaring warrBaseYrPrc in the @currWarrBaseYrPrc formula which would make it a global variable and accessible to all formulas where that same variable is declared. I thought that if I declared warrBaseYrPrc in @currWarr2YrPrc, it would have its value as calculated in @currWarrBaseYrPrc and use that. And since @currWarr2YrPrc returns the variable warrBaseYrPrc with some slight modifications depending on the if statment, it shouldn't have refused use in the Running Total.

So I'm kind of leaning more toward an ordering screw up (i.e. it didn't know what formula to evaluate first because they were all in the same section and dependent on one another because of nesting formula invocations, and thus treated @currWarr2YrPrc warrBaseYrPrc variable, and subsequent calculations, as a constant as you talked about and you can't RT constants). I still find it perplexing why it would treat a variable as a constant, but I guess I'll have to experiment with it a little bit.

By the way, do you know of any good free crystal report debugging tools?

Former Member
0 Kudos

Unfortunately I do not. Debugging in Crystal Reports is a nightmare as you have to debug one variable at a time, whilst creating a test formula and placing it on the report (especially while working with Arrays). Although when you do run into errors, a list of variables and their values will popup on the left hand side of your screen.

My advice is to not treat Crystal Syntax as you would in Java/C#/C++/VBA/Python.