views:

38

answers:

1

Hey,

So my problem is I have created a report which is grouped by Dealer number. Within this group I have created running totals to summarize the volume of each dealer, then just display their total volume. I reset all my variables to 0 in the group header. When I look at the report in CR it looks fine. But through the viewer or exported to excel -data only it just displays an ongoing running total. Seems like its not reseting to 0 in the group header. Any thoughts would be appreciated. Could problem just be with viewer if its displaying properly in CR?

In Report Header:

whileprintingrecords;
global numbervar volume := 0;

In Detail Section of Group: Formula Field

if  Month({appl_trans.trans-dt}) = 1
and Year({appl_trans.trans-dt}) = Year(CurrentDate) then (
if previousisnull({contract1.contract-no}) then
    global numbervar volume := {contract1.cost-base};
if {contract1.contract-no} <> previous({contract1.contract-no}) then
    global numbervar volume := volume + {contract1.cost-base}
else
    global numbervar volume := volume
);

In Group Header :

whileprintingrecords;
global numbervar volume := 0;

In Group Footer : Formula Field

whileprintingrecords;
global numbervar volume := volume;
A: 

Your variable usage is overly complicated and CR might be doing odd things because of it. Get rid of the formula in the report header completely - you're already reinitializing the variable in the group header. Next, change the formula in the details section to something like this:

whileprintingrecords;
global numbervar volume;
if  (Month({appl_trans.trans-dt}) = 1
and Year({appl_trans.trans-dt}) = Year(CurrentDate)
   and {contract1.contract-no} <> previous({contract1.contract-no}) then
        volume := volume + {contract1.cost-base}; 

Keep the formula in the group header as it is. Then use this formula to display the volume in the footer:

whileprintingrecords;
global numbervar volume;
volume

You generally only want to declare a variable once per formula, meaning only one "global numbervar x" and do it for every formula where that variable is used. You also will never need to set a variable to itself, as it won't actually do anything.

Another way to accomplish this that might be simpler than using formulas is that you could just add a Running Total field to sum {contract1.cost-base}, evaluate on change of {contract1.contract-no} and reset after each group. Or yet another way is to add another inner grouping on {contract1.contract-no} and insert a Summary field in the group footer. Either way will get the job done.

Ryan
I thought it was something to do with the formula declarations as well. Thanks for the advice. This however has not corrected the problem. As for your two suggestions: #1 Tried it that way first but I have to create a field for volume of each month, I just kind of simplied things for the question. Can I specify in a running total field, eval on change and reset on change a formula to only retrieve where month = x and year = year(currentdate)??? #2 Might work, I still need to specify where month = x and year = year(currentdate)... any thoughts how that can be accomplished? I'm stumped
graham jones
If you want the monthly volumes per dealer, you can create a formula that returns the month from a trans-dt if the year is current. Then, create an number array with entries for each month, selectively updating them in your details section (using a select-statement based on the month formula you just created). Now, at each group footer you'll have a volumes by month for the current dealer in each array entry (I'm making some assumptions about your data model).The problem with using a running total in this situation is that you would need one for each month, which sucks, but you could do it.
Ryan
Yes, that could work out. I will try it out. In the same breathe, will changing my report in this manner, differ any from the one I have now. The one I have created is displaying the proper values. It seems when I view it in the Cr Viewer or export to Excel- data only, it shows different values then it does in CR.
graham jones
I don't know - you will just need to do some testing. Try just doing a simple summary and/or running total and see if you get the right values when exported to Excel. I suspect that the problem has something to do with the evaluation of your formulas and the updating of your variables.
Ryan
Yea good call - thanks a lot for your help
graham jones
FYI, if anyone was wondering or had the same problem. I fixed it finally. Pretty simple too. Instead of reseting my variables in the header I reset them to 0 in the footer. DUHHH!
graham jones