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.
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 crystal report with a sub report in it. The sub report is displaying duplicates. To avoid that I used below formula.
{table.IDField} = previous({table.IDField})
Now, duplicates are removed but I have sum of the field in the footer. All the duplicate values are added to the sum. Is there a way that I can select distinct records in the sub report?
I followed below steps to solve this issue.
Created a group on the IDField
Moved all the fields from detail section to the above group header.
Suppressed the detail section.
Created the below formula and placed it in group header. I have supressed this because I didn't have to display this.
whileprintingrecords;
numbervar totalOfIDField := totalOfIDField + {IDField};
"";
Created a formula to display the above field (totalOfIDField).
whileprintingrecords;
numbervar taotalOfIDField;
This should be placed in the corresponding Group Footer.
Created a formula to reset the totalOfIDField each time group changes. Included this in the Main Group Header.
whileprintingrecords;
numbervar totalOfIDField := 0;
I have a very basic report with no groups. The details consists of a number of numeric columns. I want to add a formula field which will use a field from the first row. Example:
(ColumnAFromCurrentRecord - ColumnBFromFirstRecord) / ColumnBFromFirstRecord
Can someone point me in the right direction?
1.
Create a formula named AssignFirstValue and define it like this:
WhilePrintingRecords;
Global StringVar strFirstValue := {MYDBNAME.MYSTRINGFIELD};
Put the AssignFirstValue formula in your Report Header and suppress it.
2.
Create a formula named PrintFirstValue and define it like this:
WhilePrintingRecords;
Global StringVar strFirstValue;
strFirstValue
Put the PrintFirstValue formula wherever you want to display the first value in your report.
you need to extact the column b from first record. try below solution.
Note: This is not a tested solution as I at present I don't have CR.
create below formula Count and place in detail section:
Local NumberVar a;
a:=a+1;
This will number the rows starting from 1 to the last row.
Now create one more formula StoreB:
Share NumberVar b;
if {#Count}=1
then b:=columnb
This will store the value of columnb in first record in variable b
Now use where you want:
EvaluateAfter(#StoreB)
Shared NumberVar b;
(ColumnAFromCurrentRecord - b) / b
Let me know how it goes.
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.
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.