In Crystal Reports, How do I count all the rows in the Details section and place that count in the header? - crystal-reports

I've tried adding a new formula and used this code:
whileprintingrecords;
numbervar x;
x := x + 1;
Problem is, if I place the formula that displays the count on the header section, it only shows the first value since it hasn't yet incremented.
I need a total count of the rows in every page and just show it in the header. how do I do this?
Wait I just realized it is placed in a group not in the details section. Let me revise my question. How do I get the value of the display formula in the last page of the report? Makes sense?

The simplest way to get a total count of all the rows within the report and place it in the page header is to create a new formula, with the value:
Count ({Table.Value})
and place it in your page header (where Table.Value is a field in your dataset).
EDIT: To get a total count of all the groups, change the formula to:
DistinctCount ({Table.GroupField})

Right-click on any field in Details section, Insert Summary, select Count(), drag resulting field into page (report, group) header.

I just summarized the field with Count and put it to Group Header That's It.

Related

Crystal Report Show Total Only On Last Page

I have a formula that calculated price total of an invoice eg. #vtotal. The invoice page could span from 1 to n page. I would like to show the total only on last page. How do I do that?
I have searched and tried on some suggestions using report footer, but it does not work as it implies, the report footer always show in tandem with page footer.
I have also tried using formula:
if PageNumber = TotalPageCount then
{#vtotal}
It still display 0 on pages with PageNumber < TotalPage Count.
How to do it correctly to only show on last page? And nothing on other.
Create group over invoice ID (or whatever field identifies invoice uniquely) and show your formula in group footer.
/edit after comments/
Alternative way is to supress some formulas in page footer section. Place your {#vtotal} into page footer (like it was initially) and create suppress formula for it, with content like
{PageNumber < TotalPageCount}
You need to somehow account for situations, when you print more than single invoice - if this is possible for your setup of course.
You Can write Grand Total in Report Footer. So it will display in only last page.

How to count number of grouped rows in the Crystal Report

I need to count and show number of rows of grouped data in the report. I already have number of rows of total data in Report Footer section (I used Count() function and that works fine), but I need to have total rows in the Group Footer section which shows number of rows of grouped data. The visible explanation of the problem is shown under.
Thanks.
----------------------------------------------------
Group 1
row 1---------------------------
row 2---------------------------
.
.
.
row N---------------------------
--- I need here number of rows!---------------------
----------------------------------------------------
Group 2
row 1---------------------------
row 2---------------------------
.
.
.
row M---------------------------
--- I need here number of rows!---------------------
----------------------------------------------------
Total Rows: M+N
Try the solution
Create a formula #reset. Place the formula in groupheader and supress
Shared Numbervar count;
count:=0
Now create one more formula # Increment and place in section where there are rows I have assumed it as detail section and supress.
Shared Numbervar count;
count:=count+1;
count;
Now create one more formula #Display. Place this formula in Group footer
Shared Numbervar count;
Shared Numbervar Count_Final;
Count_Final:=Count_Final+count;
count;
Now create one more formula #DisplayFinal and place in Report Footer
Shared Numbervar Count_Final;
Count_Final
This solution may help someone,
Create a Running Total:
Choose a field
Select distinct count as Type of summary
Choose your group name in Reset section
Now drag and drop the running total field in group footer.
Refer the image below
This solved my problem
Create new formula field
{IM_INV.QTY_ON_HND}-{IM_INV.QTY_ON_HND}+1
{Existing field} minus {exiting field} plus 1
This gave me a "1" next to each detail line in a field I called {NumberForCount}
Because it was made this way it showed up in running total field options
Then made a running total field like normal in the footer
Another way to try by using Summary
Right Click > Insert > Summary
Choose Field (I choose string
value)
Choose "Count" to Calculate This Summary Combo box
Choose Summary Location in Where would you like to show this total
Then OK

Crystal report subreport displays alternative text when no records returned in subreport

How to display alternative text when no records returned in subreport?
e.g. if there is no record returned in subreport, i want to display '-'
thanks
You need 2 details sections in your report. In 1 put the what ever you want to show when you have records. Right click the same section and select Section Expert.... Check the Suppress Blank Section checkbox so this space used by this section is suppressed when there is nothing to show. In the other details section add a formula that prints what you want to display when there are no records. In your example this would be "-". Create another formula for counting records and name it RecordCount.
WhileReadingRecords;
NumberVar RecordCount := RecordCount + 1;
Place this formula in the details section of the report and suppress it. It is not important which details section you place it in. Finally, right click the same section that will show when there are no records select Section Expert.... Click the formula button for the Suppress (No Drill-Down) and add this formula...
Not Isnull ({#RecordCount})
You can see that you are only checking if the formula itself is null so the code in the formula is not all that important, but I like to make it useful in case I want to use it elsewhere in the report.
Now when you have records the second details section is suppressed and the first details section shows your data. When you have no records it is reversed and the second details section is shown while the first details section is suppressed.
Assuming you want the "-" to appear within the subreport, put it in the subreport's report header or report footer section and set the visibility of either the text item or the section (depending on whether you want the section to appear regardless of how many records are returned) to be conditionally suppressed on a formula like:
Count ({Table.Field})>0
This is one way to do it. Create a shared variable that tracks row count of sub report and then displays a text field if that count is zero.
From memory on shared fields it goes something like this... create a formula field with this code and then put that formula somewhere on the report. You can hide it so it's not visible.
shared numberVar rowcount := 0;
To set the shared variable equal to the number of rows in the sub-report. Do the same thing, (create a formula field in the sub report) but like this:
shared numberVar rowcount := <number of rows>;
There is code all over on different ways to get number of rows.
Then back on your main report make a text field that contains "-" and have it suppressed when the shared variable is greater than 0. You can also right click the subreport and set it to suppress when blank if you want.
Finally, make sure and put the text field "-" (with the suppress function) below the sub-report because Crystal won't know how many records are in the sub-report until after it tries. Crystal is funny that way.
See Crystal Reports: Display a Message When Report Has No Data
The Best way I can Suggest You is to play around with crystal reports for solutions, from your question You want to display "-" when no data present, So here is the answer:
First:1 Create an New Formula In the Sub-Report and Use editor and write the following Formula:
shared stringvar myvar;
if isnull({Id_colounm_name}) then myvar := "-"
else myvar:="+"
Note: here Id_coloumn_name is the row member which can decide the records are empty.
Second 2:
Save the formula and create a new page header section and suppress it, then add this formula to the newly created and suppressed section.
Third 3:
Go to the main report and create a new Formula, use the editor to write the following formula:
shared stringvar disp;
Save and close the formula editor.
Fourth 4:
Now insert a section below the section in which your crystal report lies.
Now go to section expert by right clicking on the section
and select formula icon right after the "Suppress" and add the following formula:
shared stringvar myvar;
if myvar <> "-" then true
else false
Save and close the formula and select the icon right after "Suppress Blank Section" and add the following formula:
shared stringvar myvar;
if myvar="+" then true
Save and close the formula, Now add the formula created in the main report to the newly created section. Save it.
Fifth 5:
Right click on the sub report and select "format object" and then select "Subreport" tab and check "Supress Blank Subreport"
and then right click on the section where your sub report lies and then goto "section expert" and then check "supress blank section"
Thats all you can do, Now run the report and check if its working or not
Note Note Note: The section containing the sub report should not contain any other text of other fields and the section containing the formula in the subreport has to be supressed and section containing the formula in the main report doest have to be suppressed.
Hope it helps
Thanks and Regards
Srikanth

Addid Static Report Titile on Crystal Report

i have faced some problem , when i want to display some static Title after i have displayed a few number of Rows . for Example , the first 4 rouws on crystal Report has header"Training " the next 4 rows mmust have "Education " Report Header.
i am trying to display the report using by calling one Stored Procedures any one who can help me please??
You could insert a new detail section above your current detail section and have the new section only be visible based on record count or some value in the data. Add a new section in the details, Format Section->Suppress and enter a formula controlling when the new section is visible. For example, a running total field named InspIDCount and this formula in the suppress section ({#InspIDCount} mod 5 <> 0) will cause a blank row every 5 records. The new section could contain a formula to display the correct "title".
I think I misunderstood your question. The number of rows for each type is probably not constant. A better way to handle this would the to insert a group into your report if the data is not already grouped. Group by the record type (Education, Training Etc). You probably want to suppress the group header but show group by footer. The footer could display a field from the database showing the type or it could display a formula (string) based on the record type. It would only take a few minutes to give this a try.

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.