Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with sum of variable

Status
Not open for further replies.

jpro

MIS
Mar 8, 2002
21
US
I am fairly new to creating variables and having trouble calculating a sum on these because Crystal doesn't let me use the standard Summary tool in this case.

Looking to find a way to create a final Sum based on my 3rd formula below that I don't know how to create.
Crystal doesn't let me make a running total on this either so it would seem I need some other variation of a variable sum or similar...?

Anyone that is understands these a little better that could help would be Greatly Appreciated.

1st Formula @Hitz Works correctly in detail section to validate if an order is considered a "Hit"
local numberVar Hitz;
Hitz := 0;

if Hitz = 0 then
if {ORDERS.ORDER_DATE} >= {?QuoteDate} then Hitz := Hitz + 1
else 0

2nd is Running Total - #ItemHits that counts by item when @Hitz > 0
This also works fine in the group footer to sum the number or hits that item has had.

3rd Formula @TIH Works in same group footer to record it as a 1 showing this item overall has been hit.
numbervar IH;
IH := 0;

if {#ItemHits} > 0 then IH := IH + 1
else 0;

The screen shot below shows the value selected that I would need to total. Currently showing as 1 but should be 2.


Thanks in Advance.



Great minds discuss "Ideas"
Average minds discuss "Events"
Below Average minds discuss "People
 
It appears the formula @Hitz should use a global variable for Hitz and initialize it in a group header. The way it is written it will only return 0 when the if statement is false or 1 when the if statement is true. Then when it is executed again it is set to 0 and the tests run again returning a 0 or 1.
 
Thanks pmsawyer, I didn't try the global variable (mostly because I am new to these). I will give that a try.

Great minds discuss "Ideas"
Average minds discuss "Events"
Below Average minds discuss "People
 
I'm not sure I understand what you are trying to do here, but a few comments/suggestions.
[ol 1]
[li]The first formula will only ever be a 0 or 1 based on whether {ORDERS.ORDER_DATE} >= {?QuoteDate}. If this is what you are trying to achieve then it doesn't even require a Variable. It could be done like this:

[Code {@Hitz}]
{ORDERS.ORDER_DATE} >= {?QuoteDate}
Then 1
Else 0
[/Code]
[/li]
[li]The Running Total could then simply Sum the result of sum the {@Hitz Formula}[/li]
[li]Not sure what you are trying to achieve with the 3rd formula but it can only ever return a 0 or 1 because it is being reset to 0 everytime it is triggered[/li]
[/ol]

Perhaps if you explained what you are trying to achieve more clearly, using sample data and the expected result, we would be better placed to offer solutions.

Cheers
Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top