Increment a number for select group header sections per group - crystal-reports

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.

Related

Duplicates in sub-report

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;

Crystal Reports: Running Total of a Group

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.

Summarizing a group header formula field in the footer in Crystal Xi

I am trying to put the summarization of a formula that is in the header in the footer. The body of the report is hidden as only the summaries are relevant.
The formula in the header is
{#orig_balance}+{rtetable.transactioncalculatedprice}.
I only want the first record of the set(which is why I have it in the header). Now I want to summarize these records and have them show in the footer.
I have two headers...the first is accounts and the second is primary ID. I have this formula in the primary id and want it summarized in the accounts.
I have been banging my head against the wall now and need some help....Please
Assuming you have two groups and hence two headers.
In group hear1 write below formula #Reset and place to left most part.
Shared Numbervar Store;
Store:=0;
In group header1 write below formula Store and place to the right of Reset:
Shared Numbervar Store;
Store:=<<Group header1 value>>;
In group header 2 Calculate write belwo formula:
Shared Numbervar Store;
Store:=Store+<<group header2 value>>;
In group footer display write below formula:
Shared Numbervar Store;
Store;
Let me know if this is not your requirement.

Crystal Reports - Selecting data in the first row to be used in a formula

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.

Crystal Reports: global variable running total not displaying in header

Using Crystal Reports I'm trying to display the running total of a database field in the header where all the labels are.
I've attempted to do this by placing the running total (RTversion) into a formula field with the following:
Shared stringvar CurrentVers;
CurrentVers := {#CurrentVers};
and then in the page header section I have the following:
Shared stringvar CurrentVers;
EvaluateAFter({#currentVers});
CurrentVers;
with {#CurrentVers} running the 1st largest number.
Is this incorrect?
Update: The goal is to display the latest version in the header near the labels to show what the current verseion is for comparison.
Running-Total Fields, in my experience, only work in the footer sections.
You will need to create a manual running total.
Add a formula field to the Details section that populates a Global variable with whatever you are trying to capture. Something like:
//use WhileReadingRecords if the values can be gathered as the report pulls in values from the database. Otherwise, use WhilePrintingRecords.
WhileReadingRecords;
Global Stringvar CurrentVers;
//logic here to capture what you want
CurrentVers:=...
Add another formula field to the Header section. Add these two lines to it:
WhilePrintingRecords;
Global Stringvar CurrentVers;
Create a formula like this
formula = Count ({Field to count},{GroupFieldName})
and place it in group header section.
I figured it out..
I had to add a subreport to the main report. I copied the main report and renamed it as a subreport. In the subreport, I added a shared variable and then passed it to the main report. The trick is to place the subreport in the same group header, but a separate section above the section that needs to be suppressed. I actually added the following sections:
New section (same group-I placed subreport here; do not suppress)
New Section (same group - I placed shared variable value here; do not suppress)
Original Section (same group that has a header I need suppressed based on a running total)
If {#CurrentVers} is a regular running total field, you should be able to place it in the page header directly rather than resort to an additional formula. I don't see the need for either formula field here, unless there's something unusual in the composition of {#CurrentVers} and a 'largest number' running total shouldn't require anything out of the ordinary.
You can solve this with just one formula field:
WhilePrintingRecords;
// Enter logic here e.g.
// maximum({mytable.myfield});
The WhilePrintingRecords; forces the formula to not be evaluated until all records have been read from the database, and therefore the formula field will display the correct result even if placed in a header.
The key I found is that the formula field being passed needs to be placed on the subreport. I placed mine in the footer then suppressed it.