Multiple Groups in jasper reports - 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

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

How to use Maximum in 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.

Crystal Reports 7 CrossTab Suppress Column

I'm trying to modify a report created in Crystal Reports 7 (which I know almost nothing about). I want to use a CrossTab, as this seems to be the best way to accomplish what I want. I have a column with three possible values: A, B, C. The cross tab creates three columns. I want to suppress C. How can I do this?
Also, is there anyway to create rows based on one field (i.e. a PK value), but display another - like a description? For example, if a list of states have a PK value of 1-50, I want them ordered by PK, but I want to display the state name.
All you ask is possible;
i suggest not to use cross tab: cross tab is intended for an uknown number of rows and columns (varying on data) ad for summarizing (max value, sum of values) results on a grid.
you should, instead:
Create a blank report
Drop the fields from the Field explrorer into the Details Section (just A and B columns)
Use Report Sort Expert to sort elements no the PK value

Flatten data inside a crystal report

Ok, this might be a weird request, but is it possible to essentially flatten my dataset inside a crystal report?
I have a datatable in C# that was created with a join, so when it hits the report its 2 records. Most of the columns have identical data, with the last few displaying a different address.
Instead of printing the detail section multiple times with mostly similar data, I need to display 1 'record' with the common data printed once, and each records address arranged next it. As in, all the common fields displayed in one area, and then next to that the address fields from the record where 'AddressType = 1', then next to that the address fields where 'AddressType = 2'
Is this a subreport thing? Because even with subreports I can't get it to only print 1 detail section with the data from just the first record.
Is this even possible with crystal? For long drawn out reasons, I can't flatten the data before it gets to the report.
Ok, someone here in the office showed me the way, so I'll put this out there.
Given data with cols A,B,C all common and D,E different across multiple rows, this is how I 'flattened' the dataset in crystal:
Create a group based on col A, and put A,B,C inside that group header - get rid of the details section entirely
Create a subreport in the group header for each row of data, in my case 2 subreports
Inside each subreport, put fields D,E. Important: There are NO links for these subreports!
For each subreport go into the Select Expert and create a condition that shows only 1 particular row of data. This conditional will have the same field for each subreport, but different values. In my case it was AddressType='A', and AddressType='B'
This will produce 1 report, with A,B,C listed once, and D,E listed once for each subreport(once for each row of data)
This was confusing, time consuming, and I hate crystal reports now more than ever.
It would be pretty ugly, but you could add a group for each common field in Group Expert and then display the data for the common fields in the last group header. So if your common fields are field1 through field5, you would create five groups and put all five fields in the group header of field5. Then you would put the unique address fields (call them field field6 through field8) in the details section.
Now the trick is getting everything to line up correctly. You can set "underlay following sections" on the group header for field5; this will cause field1 through field5 to "fall down" into the details section. You just need to make sure that field6 through field8 are all to the right of field1 through field5 so the text does not overlap.
Now, if you want the two address records to print horizontally, I think you will need a subreport with multiple columns for that. But the same principle applies -- just make sure the subreport is to the right of field1 through field5 so the data doesn't overlap.
Have you tried the suppress if duplicated option on each non-address field?
Otherwise, you could group by the common id, put the common fields in that header, and then display the multiple addresses in the details section.
Or, you could remove the addresses from the datasource and use a subreport to fetch this data for each record. This would bypass the join and be the slowest option performance wise, due to having to select the addresses for each record.
Ok, firstly let's see if I understand this right :
You want a report that would be in the format
MainDetails Address(type1)
MainDetails Address(type2)
to instead be in the format
MainDetails Address(type1) Address(type2)
?
Assuming there are only two address types, you can do the following :
1) Group by Main details (whatever the unique entry is
2) Put the address details in the group header next to them, on the right
3) Also put the address details in the details section, but positioned as if they were in the Address(type2) column positions, so it looks like :
GH MainDetails Address
D.......................................Address
4) Next, add a sort to the report on the AddressType field, so that AddressType=1 shows first.
5) Add a conditional suppression formula to the Details section saying {AddressType=1}
6) Using the Section Expert, in the Group Header tick the 'underlay following sections' box
This should work as long as the number of addresses is either 1 or 2.