How to use Maximum in Crystal reports - crystal-reports

i want to filter my rows and only select/ display my rows when the field AMSD135.AB is the latest date date in that group.
So i got a report with some groups where the last group is grouped on AMSD135.AB. Now i created a formula to hide the section.
AMSD135.AB <> Maximum({AMSD135.AB}, {AMSD135.AB})
but i always get the following error message:
There must be a group that matches this field.
if i use
AMSD135.AB <> Maximum({AMSD135.AB})
it searches for the max in all rows.

It works when i use the following formula:
{AMSD135.AB} <> Maximum({AMSD135.AB},{Arbeitsgang.AGNR})
with {Arbeitsgang.AGN} being the group above. Which makes more sense, since when i group by AB, Max(AB) is always AB. But shouldnt it still work.

Related

Display the highest value in a same column in crystal report

I am trying to show the highest values in column B which is related to each uniqe reference.I've tried this formula but didn't work.
The Data
Output 01.03.2019
This is out put from the below formula
Blockquote
01.03.2019_1
Blockquote
enter[01.03.2019_2]5 image description here
Expected Output
whileprintingrecords;
stringvar dept;
if {baseevent1.Column B} = Maximum({baseevent1.Column B},{baseevent1.Referance}) then
dept:={baseevent1.Referance}
There is an easier way to achieve your goal with less formula usage and more grouping and sorting.
You will need 2 grouping levels. The top-most group will be Referance, and then below that group on Column B. Ensure that Column B is sorted from lowest to highest. By sorting this way, the very last detail record will always contain the highest value of Column B.
Then suppress both group header section, suppress the details section, and suppress the Column B group footer section.
Place data fields for Referance, Column B, and Formula in the Referance Group Footer Section.
By grouping and sorting in this manner, when you reach the footer section for your top most grouping, the values each field contains will always be the record that had the maximum value of Column B.
No need for any formula fields at all with this approach. :)
Just do be aware, that if you ever have a duplicate value in Column B within a Referance Group, then you are going to run into issues, as this approach will print only the values of the last record in the grouped data. However, even with a formulaic approach like you began with, you were still going to run into this issue should there be any duplicates in the composite key value created by concatenating Referance and Column B.

Suppress group based on if value exists in record

What I would like to do is either suppress a group or (if possible) write this in to a selection record.
The goal would be to display all records in the group if any one of the records in the group meet the requirements.
For example if my group has three records and my requirement is that one of the records have a specific value in one field. Then display all three records in that group. Otherwise, if none of the three have that value then suppress the group.
I know where I need to put the formula and I thought the following would work but instead it only gave me the records that met the requirement not the others that accompany it.
Placed in the suppress group formula field:
if {table.field} <> "1" then true else false
Any thoughts on this?
Looks like I got it figured out. Here's what I did:
Create a Formula Field to check if the value exists in the record as follows:
if {table.field} = "X" then 1
Create a Summary Field of the formula field just created and sum the total for the formula field effectively counting how many records in that group have the value sought after.
Go to Section Expert for the desired group and Suppress using the following formula.
if Sum ({#Formula}, {table.field_2}) < 1 then true

Print field from first record in a group in the group footer

I have a series of transactions that contain a receive and return date and are grouped. In the group footer, I want to print the receive date of the first record in the group and the return date of the last record in the group. I created a formula to populate only when it is the first record in the group. But if the group contains more than one record, the formula field prints out blank. If there is only one record in the group, it prints OK. I'm using SAP Business Object Crystal Reports 2013.
There are a few ways to handle this. If you were sorting by Date, (which I've just learned you aren't) you could use a Summary to find the Minimum value. You'd place it in the relevant Group Footer and it should reset each time.
But since you're not sorting them by Date, I'd try setting up a Running Total that counts the number of records in the current Group (and resets on change of group.) Then set up a Shared Variable in a Formula that gets set every time the Group Count resets to 1. Finally, put another Formula in the Group Footer which prints out the Shared Variable.
Done correctly each Group Footer will display the first date value in that Group.

Crystal Report not sorting the group field in ascending order as it is set up to do

I have a report with three groups:
Project
RFI
Status
I am conditionally suppressing groups 2 and 3. In each suppress formula section respectively, it says
{?Sort}="RFI" (or "Status")
It does the suppression correctly. However, when it is sorted by Status, the status field is not in ascending order. Does anyone know hwy this would happen?
I can't choose a table in the Group Sort Order Formula either:
Suppressing report sections will have no bearing on how the records are sorted. A report will always have its records sorted from the outer-most group field to the inner-most group field. In your report, the records will first be sorted by "Project", then by "RFI", and finally by "Status" regardless of what you are or are not suppressing.
If you want to choose which field to sort the report by via a parameter, then you should create a formula field and sort by that instead. So something like: if {?Sort}="RFI" then {table.RFI} else {table.Status} but you'll need to get rid of your RFI and Status groups first.

Multiple Groups in jasper reports

I want to create multiple groups in ireport, and the data should display in a group-wise manner.For Eg:
First the Group1 data should be printed completely, then,
Group1:
Module Data
After this i want to print the Group2 data completely
Group2:
Category data
I am using the Result Set datasource.
Can Someone help me in this?
Jasper reports will work exactly in this manner as long as your query results are ordered properly.
For example, let's say you are grouping by a field called "MY_GROUP" and it has values "GROUP A" and "GROUP B". In your report you will create a group for field "MY_GROUP". In your query, make sure you have MY_GROUP as the first field in your ORDER BY clause. You can also accomplish this in iReports by adding the "MY_GROUP" field as your the first field in the Sort Options section of the Report query.
Now that you have added your group and are ordering properly your results will come out like this:
Header - GROUP A
Detail - GROUP A
Footer - GROUP A
Header - GROUP B
Detail - GROUP B
Footer - GROUP B
Exactly as you wish. My guess is that you were not properly ordering your query results. This could result in having multiple groupings for GROUP A, GROUP B, etc. all interspersed.
If groups in iReport don't keep all the data together, use subreports. When Jasper gets to a subreport, it runs the whole subreport and puts the whole thing into the report. You could have something like:
Subreport 1 - Group 1
Group 1 first record
Group 1 second record
Group 1 third record
...
Group 1 last record
Subreport 2 - Group 2
Group 2 first record
Group 2 second record
Group 2 third record
...
Group 2 third record
It's exactly as Tom said. Jasper Reports Groups do not order the data retrieved from the query, they just take it in the order it comes.
In order to display the information in a group-wise manner, you have to add an ORDER BY to the query so the rows the report receives are already ordered.
So there is an issue that happens when you use multiple group headers. The first header behaves like expected ordered by Column Value A only on unique values. The 2nd header using Column Value B will print on every row despite being non-unique values.
In theory you should be able to use ORDER BY:
ORDER BY ValueA, ValueB
to properly display the report assuming you are using sql, plsql, etc... However, in my case that did not happen, though for others it seems to work.
Use subreports to attach the minor differences via unique reports. You create a root report with empty details. Then you create Unique reports to serve as sub reprots. Finally, you use the subreport element to link the values into the root report. Though that is a good bit of work and may cause repeat code.
A hacky way I used was: A mixture of "Print When Expressions" with logical boolean expressions with 2 group headers and a column header.
Boolean Expressions:
$F{QUERY}.equals(Query1) && ($P{P_Typequery}.equalsIgnoreCase("QueryA") && $P{P_parameter} == null)
and
$F{QUERY}.equals(Query1) && ($P{P_Typequery}.equalsIgnoreCase("P_QueryA") && $P{P_parameter} != null)
with two group headers and a column header. The column header will not repeat for every row so you assign one of the booleans expressions to it's "print when" so it does not always print. The first group header will not repeat for every row and works. The 2nd group header is used for the times you DO want it to repeat for every unique value since it always prints for every row, and you use the other boolean on it's "print when". Hope it helps