In Crystal Reports, can you group by two tables which are both many-to-one with the top group? - crystal-reports

I am working on a Crystal Report that breaks down data first by Receipt ID, and then I need two groups both under Receipt ID, but that aren't related to each other.
So instead of three levels of grouping, I need to somehow have only two levels like following:
Group: Receipt_ID
Group: Receipt_Detail.Line_Number
Group: Receipt_Deduction.Description
Here is an example of what it should look like:
Receipt ID Line Number Weight Dollar Amount
091911001
1 17,640 $2116.80
2 16,860 $1180.20
3 17,200 $1204.00
MAC Peeler Rate 17,640 0.0027
MAC Juicer Rate 34,060 0.0011
091911007
1 40,000 $10050.00
2 13,500 $2600.00
MACMA Rate 53,500 0.0350
And so on.
Is there anyway to do this sort of thing in Crystal Reports 10?

A subreport! That would be the cleanest way.
In the receipt ID footer, insert a subreport.
In the subreport, use the Receipt_Deduction table.
In Subreport Links, select records in the subreport based on Receipt_ID = Receipt_Deduction.Receipt_ID
Move your deductions content to the subreport's detail section.
In the parent report, remove the Receipt_Deduction group, and perhaps the detail table too.
If you want, you could even move your detail content to the Detail section, so you can remove the Receipt_Detail group.

Related

Crystal Sub-report returning incorrect data

I have created a primary crystal report and attached a subreport by following the steps below;
I Created the report I want printed first as the primary report.
I then created the sub-report.
Both of these reports work fine in isolation.
I placed the subreport into the Report Footer so that it will print immediately after the primary report.
The primary report is a list of income and expenditure. The sub-report analyses the profit by cost centre. Both reports should show the same bottomline but analysed differently. (for example: Sales £100 less (list of) expenses totaling £50 = profit £50 in the primary report; £20 profit product A £20 profit product B and £10 profit product C in the sub report).
However, the subreport returns only three lines; total sales total expenses and profit and the narrative of the three lines is incorrect.
I think your subreport should go in a line before the primary line. I.e insert a line below your primary line, move the primary line into that, and put the subreport in the line where you just moved from.
Well I suppose you should look at your extraction criteria to make sure they are the same in both the primary line and the footer. I have found the following usually explain items missed in the selection.
The joins in the database dialogue - left or right joins
The selection criteria in the select expert
The group criteria - one of your records does not have a value in a group by field.

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 reports and subreports speed

I created a report in Crystal Report. It has two subreports.
GROUP Customer
GROUP FAMILY
DETAIL ITEM
The detail is for Items. This detail is inside a group. It has totals.
FOOTER A GROUP FAMILY
totals Item detail
FOOTER B GROUP FAMILY
Subreport 1 Totals by adj (it display the detail of a third table and the totals)
FOOTER Customer
Subreport 2.
Totals by item. (it display the details and the totals)
The report is 48298 records.
The tables have indexes.
Why it takes 30 minutes to run the report? Is this time "normal"?
How can I display in a footer the detail of other table?.
Can I set a field in the footer that calls a Store Procedure and returns all values like a detail?
Each of the subreports will be executed for each customer. I am surprised that you are not running out of memory. My guess is that the number of customers / families is relative small (less than 300). The report is slow because it queries the database twice for each customer. Try to prepare the data inside the main report.

Selectively showing groups in Crystal Reports

I have a report which displays information by group; I'd like to not show any group that doesn't have at least two items in it. Is there an easy way to do this?
Example:
Bob
3/1
4/3
Joe
3/2
3/7
3/9
Mark
5/9
James
John
8/17
9/2
Grouped on name, should not show Mark or James.
If your report is simplistic enough, you can get away with just suppressing the Group Header, Group Footer, and Details sections by using a summary function like count({table.somedate},{table.dudesname}) < 2. Note that the second parameter to a summary function has to be a field being used to group on.
Your mileage may vary with doing it this way. If you are displaying calculated summaries in the report footer, for example, it won't make sense to just suppress these groups as their data will still affect any report-level summary. The other problem you might run into is needing to use a distinct count on some field instead of just a count, depending on your table joins.
You could create a group-selection formula (Report | Selection Formula | Group...):
Count({table.field_to_count}, {table.grouped_field}) < 2

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.