How to show the result of a subreport only when a column value in the master report changes - jasper-reports

I want to show the result of a subreport only when a column value in the master report changes
In the picture above first two rows have same values (Test) for "Name" column.
in the third row "Name" column have FEDEX value so Name column value changing
here I want to show subreport result. similarly when "Name" column value changes from FEDEX to UPS again subreport result should be shown.

In the report designer, you can add a group. The group by expression should be the $F{Name} field. Then, if needed, you can add a group header and / or a group footer.
Everything should be in place with this. Also, you should check the comment from AlexK on your other question: Did you read about Data Grouping?

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.

JasperReports: Repeating subreport for each value of the list parameter

I need to develop a report in JasperReports which contains ONE sub-report but the sub-report is repeated for every value in the list parameter.for example :
Parameter List to be passed to ONE subreport : 1,2,3,4
MyReport :
Subreport(Crosstable+ page break) for value 1 of the passed parameter
Subreport(Crosstable+ page break) for value 2 of the passed parameter
Subreport(Crosstable+ page break) for value 3 of the passed parameter
Subreport(Crosstable+ page break) for value 4 of the passed parameter**
Then the Subreport will also contain another "sub-Subreport" that should be repated X time for each value, example :
Subreport(Crosstable+ page break) for value 1 of the passed parameter :
"sub-subreport"(another Crosstable) for value 1.1
"sub-subreport"(another Crosstable) for value 1.2
"sub-subreport"(another Crosstable) for value 1.3
In other words i'm trying to loop on the same subreport but with different data something like :
for(i=0; i<list.lenght();i++){
print(subreport(i));
}
I don't to know how it can be done. I hope my examples are clear. Thanks in advance
Your detail band will fire for each record. So, if your input control is $P{myCustomers} and your main report's query is:
SELECT customer_id
FROM customers
WHERE $X{IN, customer_id, myCustomers}
Then your main report will have one field, $F{customer_id}. Your subreport needs to have a parameter of its own and it will get a value from the main report. Insert your subreport into the detail band of the main report. Click on the subreport from within the main report, and then in the Properties window of the main report, click on Parameters. The "Name" column is the name of the parameter in the subreport that will accept the incoming value, and the "Expression" field is the value to pass. So if your subreport also has a parameter for customer id, the name is customer_id and the expression to pass is $F{customer_id}.
The iReport documentation (http://community.jaspersoft.com/documentation/ireport-ultimate-guide) has information about subreports on page 90.
Try using report groups: the group is based on a value or on expression then you can embed subreport into the group.

crystal report - repeat group header across multiple column

I have a report that has 3 columns and it is grouped by a value that i display in the group header. The report is setup to run down then across.
If the details span across multiple columns, how do I repeat that group header on the next column.
I have already checked "repeat group header on each page" in the group expert.
I have already checked "format groups with multiple column" in the Layout tab of the details section.
It will not let me insert a text object in the group header of each column.
Not sure how to do this. I could write a formula to only show at the top of each column, but not sure if there is a function to find out when the second column has started.
edit
What i want is below
Group Header Text Group Header Text Group Header Text
Detail Values Detail Values Detail Values
Detail Values Detail Values Detail Values
I would like to have the Group Header Text show at the top of each column. Doesn't matter if its the start of a new group or in the middle of the group.
thanks.
okay, I have your solution, the field, that you are grouping by , just place it on to the page header and it will repeat itself on every page until the columns of that group are finished.
Lets say you are grouping by Employee Names, just put the Employee Name field on to the page header and it should solve the issue, I jsut tried it and it worked, thanks.
There is Previous() function available in formulas that allows to show-hide a Text Object based on the change of specific field value from previous to current record.
Is this what are you looking for? Can you edit you question drawing a sample af what you have and what you want?

Merge rows of same values in jasper Repors Detail Band

My data contains same value for a particular column.
My requirement is to merge the data rows for that particular column alone in detail band.
Is it possible in jasper reports.
please help.
Thanks & Regards,
Prasanna
You can make another group, other than Detail and set the Group Expression to the same field you want.
For example, if I want to group on Country, and show Cities in each country. In "Country" Group Expression. I would write:
$F{countryField}

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.