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

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

Related

How to filter records in a single section of Crystal Reports

I have my base record set filtered with a parameter. However, this leaves me with 6 records and I need to filter down to one particular record in each of my sections. If none of the records meet my criteria i cannot suppress the section, it will need to just stay there and blank.
Essentially, I need a method to filter down records that hit one of my sections but not affect the report as a whole.
A few notes:
I cannot use a subreport for this. I need to duplicate this effort over a couple of sections and if I add any more sub reports it just crashes crystal reports (I have a lot of data & a ticket with SAP)
Using a suppression formula hasn't worked yet because I need the section to exist, if it has a null value
Applying no filter doesn't help me because it will duplicate my section 6 times
2 options.
a)
Right Click on white space and choose Insert Group
Choose your field and select specified order or use another record that can filter your data
On the Specified Order Tab click New
Select equal to on the combo box and specified what record you need to be shown
or
b)
Right click on the record
Next to the suppress check box, click on x-2
Here you can create a formula to suppress the records that you don't need.

Organizing Multiple Details Sections in Crystal Reports 2013

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.

Crystal Report suppress a whole row in details section

I am using crystal report in my vb.net program. Because of my database design I get some rows duplicated as in the following picture:
As you can see from the picture, the first record has two printer models that have the same ink group. and the next model is the only model that has that particular ink group. As I have mentioned before This is because the way I designed the database and its not the problem. I know how to suppress a single column.
When I select a column and check "suppress if duplicate", the following results show:
The row is suppressed but also has taken a place in the report details.
My question now is how to suppress a whole duplicated row?
thank you
As you are aware that your database design is producing these type of results, one option would be check the option Select Distinct Records so that only distinct records are displayed.
One more option.. This is not a tested one change as you required, This is just an idea
write a condition in supress of the section where you placed your data.
if ID=next(ID)
then true
else false
This condition will make sure that if next row is duplicated then it will be supressed
there is many Options , Easy one Is,
you can use Grouping in Crystal report , in your Example u can Group on ID then Suppress Group Detail and Group Footer Problem Solve Have Fun with Coding

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.

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.