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;
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.
Related
I have a formula that uses two shared numbers in it. I now need to sum this formula. If I use running total or sum functions, the formula does not show in the pick list.
The formula I need to sum is called "excel formula" and this is the calculation the formula is doing:
({#Shared Total Wt Lbs}*{#Shared Scrap})/100
The "usual way" of creating a sum or running total does not work for a formula that holds a variable .
To get a sum of it you'll need to use a third variable.
Place the following formula in detail-section to add up the values:
WhilePrintingRecords;
NumberVar SumOfExcelFormula;
SumOfExcelFormula := SumOfExcelFormula + {#excel formula}
Use the following formula to show the sum:
WhilePrintingRecords;
NumberVar SumOfExcelFormula;
To reset the sum on every group change, put the following code in a formula-field and place it on the group header:
WhilePrintingRecords;
NumberVar SumOfExcelFormula := 0;
I have running total of a group, works fine but doesn't reset after every group.
My group header Formula:
whileprintingrecords;
numbervar SUM_A:=0;
numbervar SUM_B:=0;
Next I have a suppressed formula in the Details section:
if ({REPORT_DATA.A} = "Y") then
(shared numbervar SUM_A:=SUM_A+{REPORT_DATA.SUM_OF_A};)
else if ({REPORT_DATA.BM} = "Y") then
(shared numbervar SUM_B:=SUM_B+{REPORT_DATA.B};)
In the group footer I have several formulas as such:
whileprintingrecords;
shared numbervar SUM_A;
SUM_A;
Up to here everything works fine and the numbers add up. However, when the report continues and the second group begins, the SUM variable does not get reset (my understand is that it should because of the formula in the group header).
Any help would be appreciated.
Either your SUM_A variables are not the same or they are not being evaluated in a consistent way. Try the following:
Firstly, declare the variables consistently as either:
Shared numbervar sum_a; or
Numbervar sum_a;
... These are declarations for two different variables! Only add 'shared' if variables are being used in subreports and the main report.
Secondly, if you are using whileprintingrecords you generally need that in the other formulas working on those variables. So, add whileprintingrecords to the top of the other formulas with sum_a variables.
I have no idea why this didn't work.
I solved the issue by putting the formula field that zeros out the totals AFTER they have been displayed, in the group footer.
I am able to pull a field out of the sub report with
shared numbervar sub1Total;
but I need to add them up at the end of group. If I try and do a sum on the field in the main report I get an error that that field can not be used with sum.
You can add up the values passed back from the subreport by keeping track of them via a global variable in the main report.
//Initialize the variable in the Group Header of the main report
whileprintingrecords;
numbervar groupsub := 0;
//Update the variable in the Details section of the main report
whileprintingrecords;
numbervar groupsub;
shared numbervar subval;
groupsub := groupsub + subval;
//Print the accumulated group value in the Group Footer of the main report
whileprintingrecords;
numbervar groupsub;
Note: only works if the sum
groupsub := groupsub + subval;
is in Details Section
I have a unique question that I am not sure is even possible.
I have a report that has several Group Headers per group. What I would like to do is have select Group Headers (GH1a, GH1p, GH1w...) have an auto incremented number, which I will then turn into an roman numeral using roman(#function). The numbering would be independent on the number of actual groups, only Group Headers. There could be one to 100,000 records (groups) returned to the report but for each record(group) the Group Headers within each group would have select Group Headers numbered the same
EX:
GROUP A
GH1a: I
GH1b:
GH1c: II
GH1d: III
GH1e:
GH1f:
GH1g: IV
GROUP B
GH1a: I
GH1b:
GH1c: II
GH1d: III
GH1e:
GH1f:
GH1g: IV
etc....
Any help would be appreciated. I have tried to use a global variable x in both the report header and each GH that I want incremented using the following code:
in reportheader and/or GH1a //#iCountreset
Global NumberVar iCount:=1;
in each GH that I want incremented //#iCounted
Global Numbervar iCount;
iCount:= iCount+1;
then a second one to romanize it //#RomanCount
roman(#iCounted);
I currently have them hard coded but am trying to combine several rpt files into one where the only difference would be some GH sections would be suppressed and therefore not counted in the numbering.
Thank you in advance.
//{#reset}
WhilePrintingRecords;
Global Numbervar G1:=1;
//{#increment}
WhilePrintingRecords;
Global Numbervar G1:=G1+1;
//{#roman}
Roman({#increment})
** edit **
Ryan's comment was correct. My new approach uses subreports to increment a shared variable, which works.
Steps:
add {#reset} GH1a of 'main' report; suppress
//{#reset}
WhilePrintingRecords;
Shared Numbervar G1:=0;
create a subreport; place it in GH1b; add these formulae to it:
add to Details section; suppress:
//{#increment}
WhilePrintingRecords;
Shared Numbervar G1:=G1+1;
add to Details section:
//{#roman}
Roman({#increment})
You will need to add this subreport to each section that requires a Roman-numeral calculation. To make this process a little less painful, export the subreport ('save subreport as'), then reinsert it.
Hi i have a long formula field which I would like to include as the cross tab report summary field. However after I define the formula field I don't see it in my crosstab screen. How to include it ?
Here is my formula field
WhilePrintingRecords;
numberVar rt;
numberVar layMdp;
numberVar totMdp;
rt=Round(({Command.GENGNPIAMT}/{Command.TOTALGNP})*100,2);
layMdp:={Command.GENPREMMDP};
totMdp:=(layMdp)*Truncate((rt/100),4);
Also if I place this formula field inside details section, it shows a zero. Why is it not calculating anything ? I like it to calculate values as per each cross-tab column.
You're setting the variables but the formula itself is not returning anything. If you want to return the value of totMdp, just add it after the last line:
WhilePrintingRecords;
numberVar rt;
numberVar layMdp;
numberVar totMdp;
rt=Round(({Command.GENGNPIAMT}/{Command.TOTALGNP})*100,2);
layMdp:={Command.GENPREMMDP};
totMdp:=(layMdp)*Truncate((rt/100),4);
totMdp