How to sum running total field for each group in crystal report? - crystal-reports

i have problem in crystall report,
Here is my code following many reference site in google,
// {#reset}
//place in group header
whileprintingrecords;
global numbervar Sum_Cumm_Sum:=0;
// {#increment}
//place in section detail
whileprintingrecords;
global numbervar Sum_Cumm_Sum:=Sum_Cumm_Sum+{#getIP};
// {#display}
//place in group footer
whileprintingrecords;
global numbervar Sum_Cumm_Sum;
Where getIP is Formula,
{#sumKN}/{#sumSKS}
and code in it is running total field with reset on change group,
{#sumKN} is running total field for field KN
{#sumSKS} = is running total field for field SKS
============================================================
I use all this code, but in Sum_Cumm_Sum:=Sum_Cumm_Sum+{#getIP}, I can't get the right value.
Here is my report view:
http://i.stack.imgur.com/CSmsB.png

To the extent I see as you placed in detail section your formula is working correctly, Now you want to see the summation of values in footer then you need to write saperate formula to sum index.... in footer section so that it sumarizes it saperatley.

Either use a manual running total OR a running-total field, not both. By the way, a running-total field only works in a footer section.
A better approach:
{#sumKN} - field is {table.KN}; summarize for all records; reset after change in group
{#sumSKS} - field is {table.SKS}; summarize for all records; reset after change in group
// place in `footer` section
//{#ratio}
// optional
// EvaluateAfter({#sumKN});
// EvaluateAfter({#sumSKS});
{#sumKN} / {#sumSKS}

Related

Crystal Reports 2016: How to Suppress Page Footer when Group Footer is Rendered?

I've been asked to modify a Crystal Report that has a regulatory statement. When the report is rendered, regardless of the page where the statement is rendered, the given page footer contents must be suppressed. Is there a way to hide the page footer when the regulatory statement is displayed? The statement is an OLE object in Group Footer 3 of the report.
I've created a formula as follows:
WhilePrintingRecords;
booleanVar SuppressFooter := false;
I've placed the formula in the report header, mainly to initialize the variable.
I created a similar formula and placed it in group footer 3 and set the variable to true. I then reference the group footer 3 formula in the Suppress formula of the page footer section expert. Unfortunately, this suppresses the page footer for all pages associated with a given record.
Is there an operand that can be used that states - When group footer 3 is printed, set SuppressFooter:= true? Ideally, I would insert this logic in the Suppress formula of the page footer section expert.
How would I achieve the intended functionality?
Update
It was suggested to move #SuppressFooter to the Group Header 3. It's defined as
WhilePrintingRecords;
BooleanVar SuppressFooter := false;
I also added #SetSuppressFooter to the Group Footer 3. It's defined as:
WhilePrintingRecords;
BooleanVar SuppressFooter := true;
The formula used to suppress Page Footer is defined as:
WhilePrintingRecords;
{#SetSuppressFooter} = true;
Snippets of the report structure are also included:
The above logic is still not suppressing the page footer when Group Footer 3 is rendered.
First, the formula used to suppress Page Footer should be defined as:
WhilePrintingRecords;
BooleanVar SetSuppressFooter;
Then, if your formula #SetSuppressFooter is placed in group footer, it is evaluated even when the group footer is suppressed by condition. I.e. in order to set the variable conditionally (= when the footer is printed) it's not sufficient to place the field within the section, but one must include the logic here:
WhilePrintingRecords;
BooleanVar SuppressFooter;
If {Befehl.showgroup} = 1 Then SuppressFooter := true Else SuppressFooter := false;
You have to replace {Befehl.showgroup} = 1 with your own condition of course, i.e. the one that controls group footer's section visibility.
That leads to one last point: Depending on where the page breaks are located in your report, it could be easier to use the opposite logic for page footer visibility as for group footer visibility. In this case there's no need for "WhilePrintingRecords" formulas.

Crystal Reports - columns line displayed on the last page even there are no records

I have used the following code in a formula in order to count the records:
Shared NumberVar PageofLastField;
If OnLastRecord then PageofLastField := PageNumber;
Also, for page header, I have used the following code in a formula in order to suppress report header if there are no records:
Shared NumberVar PageofLastField;
PageofLastField := PageofLastField;
IF pageofLastfield <> 0 and PageNumber > PageofLastField
THEN TRUE
ELSE FALSE
But still, on the last page, the lines between columns are displayed like a dot (please see printscreen). Can anyone help me? Thanks
Make sure this is not the case with your report.
this happens when you have drawn a line in header section but there is a small portion coming out to the next section. just drag the end point to the same section where the line was started in. This should solve it.

Hide or show image based on column values

I'm working on a report in which I need to show or hide images based on the values of a column. E.G: if the value 18 doesn't exist in the "Details" section, the image 18 must be hidden as described in the attached photo
I tried to use an array in which I inserted the values of the column I need to use. This is the supress expression I tried to use.
shared numbervar array MyArray;
MyArray:=makearray({MyTable.MyColumn});
local numbervar i;
local booleanvar result = true;
for i:=1 to ubound(MyArray)
do
if (MyArray[i] = 17) then
result := false;
result
I realize that the images aren't hidden because I'm working on the Page header and I can only access the first line of the table.
Because you're suppressing the images in the page header, you're limited to simple aggregate functions and won't be able to use variables, running totals, etc.
It's not hard but it is tedious because you'll have to create one new formula for each value.
//#CheckValue1
if {table.value}=1 then 1 else 0
//#SuppressionValue1
// If this evaluates to 'true' anywhere in your report, including the PH,
// you know value 1 does not appear in your report
maximum({#CheckValue1})=0

Passing Subreport Value to Main Report

In my Report I am passing the Total of Subreport to display in the Main Report for that I am using the below Formula,
In Subreport,
WhilePrintingRecords;
Shared Numbervar EvTotal:= cdbl({Evaluation_Details.NOOFCOPIESEVALUATED})
In Main Report,
Shared NumberVar EvTotal;
EvTotal;
but when I Include the Formula for displaying in the Main Report it is Dispalying "0" instead of Total of SubReport
A couple of things:
You have some typos in your code. Here you were missing the semi-colon at the end:
WhilePrintingRecords;
Shared Numbervar EvTotal:= cdbl({Evaluation_Details.NOOFCOPIESEVALUATED});
And here you don't need the semi-colon:
Shared NumberVar EvTotal;
EvTotal
And as #Raphael pointed out, it is important that you have the subreport higher in the hierarchy than the formula in the Main Report that calls the variable. I would also suggest to have "WhileReadingRecords;" in both, that way you ensure they evaluate at the same time. Also, as a little debugging help, put "EvTotal" at the end of the first formula, that way you can see what the value is/should be.
The formula that you created in the sub-report must be placed in the detail section or Group header. You can hide this field. Then it will show up the correct value.

Suppress Page Footer After Subreport

I'm trying to suppress all the page footers on the main report on all pages that have a subreport and I'm having some trouble.
The subreport is in the report footer and starts on a new page. The subreport could be 1 or 10 pages so doing it by page number is out.
I've tried setting a global variable in the main report header and setting it to false and then changing the variable just before the subreport section (I change the variable in report footer a, and then the subreport is in report footer b) to true and then tried to suppress the page footer based on that global variable but to no avail.
I feel like I'm really close but just missing something. Any help would be awesome.
Hi Try this it will work
1) Create this formula and place it on the Group Header 2 Section:
whileprintingrecords;
numbervar x := x + 1;
"";
2) Create this formula and place it on the Page Header Section:
whileprintingrecords;
numbervar x := 0;
"";
3) Go to the Section Expert > Select the Page Footer Section > Click the formula button beside 'Suppress' and use this code:
numbervar x = 0;
Let me know how this goes.
You have the right idea, but are probably just missing a detail or two.
In the report footer, create a global boolean variable and then suppress the page footer based on this variable. BUT, you need to use the whileprintingrecords keyword for both formulas. Ex:
//Declare variable in report footer
whileprintingrecords;
booleanvar suppressFooter := true
//Suppress page footer
whileprintingrecords;
booleanvar suppressFooter