How can I create grand result in crystal report? - crystal-reports

I have a field there in my report its called result. It shows something like that
PASS
PASS
PASS
PASS
or
PASS
FAIL
PASS
PASS
I want to make a custom formula to show grand result. If that specific(result) field keeps all PASS value then it will show PASS there in grand result else it will show FAIL(If result field keeps at least one fail value.) I don't have enough idea about crystal report scripting so would you please show me example? I have used following code if {res_info.res} = "PASS" then
"PASS"
else
"FAIL"
but it shows pass if last row gets pass value & shows fail if last row gets fail value. All I want to do it that it will check all values of result field & if it gets at least one fail value grand result will show fail else it will show pass. I am just a beginner so please add example with your answer.

There are a few ways to accomplish this. The quick and dirty way is to add a Summary field. Right-click on your result field and select "Insert" then "Summary". Select the minimum aggregate function under "Calculate this summary" and select "Grand Total (Report Footer)".
This will return the minimum value for that field (in the case of a string, the minimum in alphabetical order which is FAIL if it appears, otherwise PASS) for all records.
I'm on Crystal Reports 2008, so your version's steps might be slightly different.

You can keep a second variable that instead of storing either "PASS" or "FAIL", it will store 0 for "Pass" and 1 for "Fail".
Then, in the grand total, you can create a formula field that takes the SUM of your variable, and if it is greater than 0, show "Fail"; otherwise, show "Pass".

Related

Crystal Report create separate report pages based on field value change

Looking for some advice related to data grouping and printing in Crystal Reports.
I'm working with an order confirmation form. Ideally I would create separate report pages based on a specific field value change for the 'warehouse' field. So, if any given line on an order comes from warehouse A, it prints together. Then we'd get a page break, and we'd see the form repeat for any lines coming from warehouse B.
I've inserted a new group for "warehouse" and configured the group as 'New Page Before.' But when I attempt to print I'm getting an error related to "There must be a group that matches this field". So there must be some pre-existing grouping that I'm not considering. I'm hopeful I can figure this out.
I am interested to get thoughts on overall design, and if the grouping approach I am trying to take is even the correct one.
Somewhere in your report you probably have a formula such as:
Sum({some_value}, {some_field})
where the {some_field} used to be -- but is no longer -- grouped upon.
Fix that expression to set the desired aggregation level (the 2nd argument) to a field you are actually grouping on.

Group data based on different size

I am trying to make a report in which I need to show data based on Width groups. Below is an example of data & the required output. I'm unable to make a group which can give this required output. If someone can help please.
The easiest way to accomplish your grouping needs for this data set would be to create a new Formula Field that evaluates the values of the Width data field for each record to determine which group the record belongs within, then do the grouping on this new formula field.
You formula field will look like this.
Select {WIDTH}
Case 400 to 600 :
"G1"
Case 601 to 849:
"G2"
Case 850 to 1049:
"G3"
Default :
"Default text or error message text goes here"
You will likely need to adjust the integer values I'm used in the Case statements to evaluate the WIDTH field. The text that goes into the Default case is up to you. In fact, if it works logically with your needs, you could eliminate the Default case entirely, as it is not required. However, it is good practice to ensure the Switch statement always returns a value, even if that value is text to indicate that something unexpected occurred. This allows your users to easily recognize a bit of a data that may be out of range for the grouping of the report so the report can be modified or the data can be corrected, whichever is the most appropriate action.
The other 3 columns in your required output appear to just be counting the number of records within each group that have a diameter within a range. To get this output you can use Running Total Fields with a Type of summary of Count and then use the range of values in the Evaluate section. The Reset section will be set to On change of group evaluating the group created by the formula field above. You will want to put a sort order on the diameter field though.

Updating a variable whith a value returned by a subreport

I have a main report which loop over query's data on detail1 band.
In this main report I call a subreport which takes an integer in input parameter and returns a string in result (it does not display anything actually).
If I want to use this subreport once, it works and the returned value is affected to a variable that I can display in my main report.
But I can't make it works when I have to updates the variable in each iteration of detail1. In this case it displays null, or the result of the previous calculation.
I guess it's all about reset type and reset group but I'm really stuck here :(
PS : I'm using jasperserver 3.3.x
The returned variable is only available when the whole band is "printed". Try placing the variable in a text field in the same band as the subreport (detail1) with an evaluation time of 'Band'.
Also if the subreport isn't actually displaying anything you may be able to do what you want with a scriptlet instead.

How to calculate sum of a formula field in crystal Reports?

In some inherited code, I see group headers/footers have items like 'Sum of #numcount' . I cannot get the sum of a formula field. Any thoughts?
The only reason that I know of why a formula wouldn't be available to summarize on is if it didn't reference any database fields or whose value wasn't dynamic throughout sections of the report. For example, if you have a formula that returns a constant it won't be available. Or if it only references a field that is set throughout the report and returns a value based on that field, like "if {parameter}=1 then 1" would not be available either.
In general, the formula's value should not be static through the sections of the report you're summarizing over (Though the way Crystal determines this is beyond me and this doesn't seem to be a hard and fast rule)
EDIT: One other reason why a formula wouldn't be available is if you're already using a summary function in that formula. Only one level of summaries at a time!
(Assuming you are looking at the reports in the Crystal Report Designer...)
Your menu options might be a little different depending on the version of Crystal Reports you're using, but you can either:
Make a summary field: Right-click on the desired formula field in your detail section and choose "Insert Summary". Choose "sum" from the drop-down box and verify that the correct account grouping is selected, then click OK. You will then have a simple sum field in your group footer section.
Make a running total field: Click on the "Insert" menu and choose "Running Total Field..."*** Click on the New button and give your new running total field a name. Choose your formula field under "Field to summarize" and choose "sum" under "Type of Summary". Here you can also change when the total is evaluated and reset, leave these at their default if you're wanting a sum on each record. You can also use a formula to determine when a certain field should be counted in the total. (Evaluate: Use Formula)
You Can simply Right Click Formula Fields- > new
Give it a name like TotalCount then Right this code:
if(isnull(sum(count({YOURCOLUMN})))) then
0
else
(sum(count({YOURCOLUMN})))
and Save then Drag and drop TotalCount this field in header/footer.
After you open the "count" bracket you can drop your column there from the above section.See the example in the Picture
You can try like this:
Sum({Tablename.Columnname})
It will work without creating a summarize field in formulae.

How can I conditionally group items in Crystal Reports?

I have a report that is currently separated into two reports, and I'd like to merge them.
Basically it boils down to this:
I ask the user if they want to have a page break for each Property, if they answer yes, I sort/group by Property and then I sort by X
If the user answers no, I want to just sort/group by X
I've tried suppressing the initial Grouping if the user answers No, but it still sorts accordingly (not how I want it to).
How can I do this without keeping it in two reports?
Instead of suppressing the grouping field, try setting it to an empty string "". I was just working on a report last week that was very similar. Even if 'no grouping' was selected, the report was still being grouped by some unknown default. In the formula grouping field, I found that if 'no grouping' was selected the field was not getting set at all. Once I changed it to set the field to an empty string, the report generated as expected.
Are you grouping or sorting? If you do not use the group header/footer it is basically the same as sorting and you should simply use the record sort.
In general, to conditionally group fields you would use formulas. For this to work the fields in question need to be returned as the same type: number, string, date, etc. In your case it sounds like the first grouping formula would be like this...
//{?break_by_property} would be the parameter value to control the page break
if {?break_by_property) then
{the_property_field}
else
"" //any static value of the same type as {the_property_field}
now go the "new page before" formula for that group header and enter this boolean formula (groupnumber is a special keyword)...
{?break_by_property} and groupnumber > 1
then add a record sort for X.