Organizing Multiple Details Sections in Crystal Reports 2013 - crystal-reports

I'm creating a report in Crystal Reports 2013 that will show the same metrics for a variety of different views. I'd like to layer them on top of each other vertically in different detail sections.
I'll try to explain best I can. I'm inserting the first query into the first report detail ('Details a'); this query has two rows.
I'm then inserting a similar query into another details section ('Details B'). I'd like each row in Details A to presented at the top of the report, and then each row of 'Details B' presented underneath that( So:
Details A Row 1
Details A Row 2
Details B Row 1
Details B Row 2
My problem is, when I go to Preview, the rows are organized like this:
Details A Row 1
Details B Row 1
Details A Row 2
Details B Row 2
Is there anyway to format Details sections so I can keep all rows within each details section next to each other? Please let me know if more information would be helpful.

Use 2 subreports (Insert, Subreport).
This would allow subreport #1 to show all details rows from one data source.
And subreport #2 would show all details rows from the other data source.

What is going on is a cartesian product. In other words, the set of your first query brings 2 rows, while the set of you second brings another 2 rows. So, 2x2=4 rows.
Another thing to notice, is that details A and B are not independent. That is not very intuitive, i know. Let me try to tell you how Crystal deal with that (it is not how it really works, just an helpful view to understand it):
Crystal executes your two queries.
The result of the first query has 2 items, namely 1 and 2.
The result of the second query has other 2 items, namely 3 and 4.
Crystal check the link between the two result sets. Since - i suppose - you did not tell to Crystal what is that link, Crystal suppose there are no links, so it makes the cartesian product resulting in 4 rows, namely 1/3, 1/4, 2/3, 2/4.
Then Crystal makes a kind of "foreach" statement. So, foreach of the 4 rows, it prints one instance of the details section.
Since your details section has 2 subsections, namely details A and details B, it will end up with 4 details printing, as you saw:
1 //1st detail section, subsection A, field from 1st result set
3 //1st detail section, subsection B, field from 2nd result set
1 //2nd detail section, subsection A, field from 1st result set
4 //2nd detail section, subsection B, field from 2nd result set (second item)
2 //3st detail section, subsection A, field from 1st result set (second item)
3 //3st detail section, subsection B, field from 2nd result set
2 //4nd detail section, subsection A, field from 1st result set (second item)
4 //4nd detail section, subsection B, field from 2nd result set (second item)
So, as #MilletSoftware already pointed out (while i was writing this, hahah), the simplest solution is to use two subreports.

Related

Conditional Printing for Front and Back page

I'm using iReport 5.2.0 and I have 2 reports that I want to print.
Both reports contain dynamic data and can be of multiple pages. However, number of pages of first report is always equal to number of pages in second report.
In my current setup, the first report is always printed completely and then all the pages of the second report are printed.
However, my requirement is that the report should print in the following sequence:
Page 1 of Report 1.
Page 1 of Report 2.
Page 2 of Report 1.
Page 2 of Report 2.
Page 3 of Report 1.
Page 3 of Report 2.
...
Is there any way I could achieve this with JasperReports?
Lets say , report 1 uses X query with X_SQL and report 2 uses Y query with Y_SQL.
If both of the query has same number of column then it is great otherwise add additional column with respect to X_SQL and Y_SQL in order to union both query.
Remember you have to generate one number series column and one dummy column in your sql. You can generate number series dynamically in your sql.
X_SQL with two new column (number_series,'detail1'as dummy)
union
Y_SQL with two new column (number_series,'detail2'as dummy)
order by number_series, dummy
OUTPUT of SQL:
X_SQL column , 1 as number_series, 'detail1' as dummy
Y_SQL column , 1 as number_series, 'detail2' as dummy
X_SQL column , 2 as number_series, 'detail1' as dummy
Y_SQL column , 2 as number_series, 'detail2' as dummy
Now add two detail band in your new report. Height of report is only one detail band height + top and bottom padding.
1 detail band = first report design
2 detail band = second report design
U can use subreport if your jrxml is too complex.
Now in print when expression of detail band use
detail band 1 : $F{dummy}.equals('detail1')
detail band 2 : $F{dummy}.equals('detail2')
Note:
1) you need to order by in your sql query.
2) height of report need to choose properly.
If still you are having issue then i suggest to post your jrxml.

Form prints multiple times when more than one record is pulled in sub report 2

In Crystal reports I am making a summary statement and I got all of it but 2 parts are giving me trouble... I have two sections that needed to be totaled so I made subreports and put them in detail a and detail b. Each section potentially can have multiple sections or no sections. whenever there is more than one line in detail b or sub report 2 it prints the whole report that many times. So if there is only one record in Detail B it prints like
header a
detail a
footer a
header b
detail b
footer b
But if there is 2 records in detail b it prints
header a
detail a
footer a
header b
detail b
footer b
header a
detail a
footer a
header b
detail b
footer b
And the pattern continues if there is 3 records in detail b.
I also need to subtract the total of detail b from detail a. I can grab the number i need from detail b but whenever i try to get the total from detail a it comes back as a 0 instead of the number. Please Help me! Thanks
review your links or create a group on your subreport, so it won't show same info 2ice. Take in consideration that if you are using shared or global variables to show totals from your subreport, it should be place in a different section of your subreport. For example:
If your subreport is on Details Section A, you should place your variable in Section B.
try placing those subreports in your report header rather than your details. Create another 2 RH sections and place them on it

Repeated values in subreport. Too many pages

I have a report with 2 suppliers. I want to show items ordered by the 2 suppliers. For that I am using a subreport.
For the 1st supplier there are 15 rows and second has 1.
But there are 2 many pages displayed. i.e. 92 pages. The values are repeated. Also a lot of empty pages are shown.
Please advise.
https://www.dropbox.com/s/i5n3z80m7c2itlt/Complex1.jrxml
https://www.dropbox.com/s/5qm5o9cz1yatfad/subcomplex.jrxml
Mithnil,
In the complex1.jrxml query, how many rows are returned? You put the subreport in the detail band, and without any report groups it will execute whatever is in the detail band for each row of the report query. Maybe you need to work on the query to only include one row per vendor.

Crystal Report - two detail sections each showing their own subset of data

Is it possible to have a Crystal Report with two detail sections with each showing a subset of the results returned from the SP that the report is linked to?
For example in DetailA I want the records where FieldA in (a,b,c) and in DetailB I want records where FieldA in (d,e,f)
I know there is the Select Expert that can be used but that seems to work across the whole report rather than each individual detail section
It would be nice if I didn't need to create formulas as there are about 20 fields in the detail sections. Is there some kind of master formula that can be applied to the detail section as a whole?
You can do this pretty simply by just setting up your two Details sections the way that you want and placing all of the records' fields you want to display in each. Then, add a suppression formula to each of the Details sections. You can access the suppression formulas of each section by right-clicking that section, choosing 'Section Expert', and then clicking the formula button next to 'Suppress (No Drill-Down)'
Detail Section A: not({table.fieldA} in ['a','b','c'])
Detail Section B: not({table.fieldA} in ['d','e','f'])
Now, your Details A section will only display when the record is of type a, b, or c and your Details B section will only display when the record is of type d, e, or f.
While Ryan's method will work, it is a good idea to add to it and group by a formula field:
if {table.fieldA} In ['a','b','c'] then
'Group 1'
else
'Group 2'#
Then add the suppression formula for details A & B as:
{#MyGroup} = 'Group 2' and {#MyGroup} = 'Group 1'
This provides three benefits:
It will automatically sort the two sections into Group 1 and Group 2
It will only ever show one or the other, and always show one, Ryan's method could hide unexpected details which can cause problems
It is much easier to maintain as you're not keeping different lists in different sections

Hide a column in cross-tab depending on the value of parameter (Crystal Reports XI)

I'm using Crystal Reports XI (R2) and have a cross-tab which displays information about flights. There is the 'Total' column' as well as the Arrivals and Departures columns which are created automatically thanks to the grouping condition. What I'm trying to do is to have the 'flight directions' parameter, where the user can select 'All, departures only or arrivals only' values and according to this selection the cross-tab would have one or two columns. How can this be achieved? I tried using the following formula(and have the suppress empty columns option enabled) :
if {?Pm-#flight_direction_description} = "Departures Only"
then
if ({Command_1.IsArrival} = 1)
then 0
else {Command_1.IsArrival}
which indeed works (only one column is displayed) but then under the Departures column it lists all the flights (so the departures column is the same as the Total column) whereas it should only display information about departing flights.
I've had similar situations come up; while certainly not ideal, and if no one has any better suggestions, you could create Detail A, Detail B and Detail C sections, all of them suppressed. From there...
You could put your "All" crosstab in Detail A
Create a second crosstab for Destinations only, and put that in Detail B
Create a third crosstab for Arrivals only, and put that in Detail C
Then, in your Detail A, B and C sections, you can condtionally unsuppress the section you want based on the parameter passed in.