Crystal Reports Record Filtering using and - crystal-reports

Currently I have a crystal report that only shows orders which included a "Storm Door" OR a "Sunroom Component". However I would like it to only show orders that include BOTH "Storm Door" AND "Sunroom Component" within a order. Any suggestions on how the code for this might look?

I think you have answered your own question - If you want the report to retrieve records where BOTH products were ordered, you would use an AND statement - {Categories.Description} = "Storm Doors" and {Categories.Description} = BetterView Sunroom Compnents". However, the issue with duplicate records sounds like a problem with the design of the report. You could try a few things
Look at the table joins and verify they are setup correctly; if you have a 'one to many' join setup, you may be retrieving multiple rows for each record. If you joined Customer to Orders on the Customer_ID, you would get every single order for each customer, etc.
Click Database > Select Distinct Records - Depending on how your report is configured and which fields you are displaying, this may remove the undesired duplicates.
Change your grouping order - Instead of grouping by Category (Storm door, Subroom), group by Customer and then count the number of orders or use an aggregate function to give you the information you need.

Related

How do I use the Detail Section when I have multiple Tables

I recently had to take over creating reports using CR 2013, but the introduction I got was kinda lackluster, so from time to time I run into some Problems.
Recently I had to use the detail section for the first time since I was somehow able to handle previous reports with just grouping and Subreports.
Now, what I was doing was create a report listing certain personal assets for each person in a table.
First I grouped by Organisation, then by Person and then put the field with their assets into details.
This worked fine until I was supposed to attach a subreport that should only be shown if it contains any records.
In my first attempt I attached the subreport in the report-footer and suppressed the section if the ID-Field for the main object of the Subreport was Null.
But that caused all personal assets in the detail-section to be duplicated, I guess because it reprinted the details for all records in both the table of the original, and of the subreport.
I solved this by removing the table from the main record and suppressing the subreport within itself.
But is there a solution to only print a detail section for the records of a specific table? Is there even a reason to do that? I am asking since I want to be sure I understand such concepts going forward.
Thank you in advance.
I understand that the introduce of the second table caused the repetition of details because it lead Crystal to make a cartesian product of the two tables.
Let's call the two tables like this to facilitate: TableA, TableB.
When you use only the TableA, think that Crystal do this:
select * from TableA
Then you introduce TableB, then Crystal would do this (just a mental model, I am not saying it does it really):
select * from TableA, TableB
If you understand SQL, you will notice what happens: a combination of all elements in both tables.
Then, the details section will consider each result of this combination.
Ex: TableA = {1,2}; TableB = {X,Y}; Result = {1X,1Y,2X,2Y}
In general, there are two approachs to avoid this. I don't know which one is applyable, since I don't know all the details of your case.
Let your main report know about the TableA only and the subreport know about the TableB only.
Create an extra group (surrogate, innermost). It should group by an unique value in TableA (an Id value would be great). Then you move the fields from details section to this new group footer section and suppress the details section.
There is another approach: create a link between both tables, but it is possible depending on the data, so I can't claim it will work. That would lead to Crystal to do something like:
select * from TableA, TableB where TableA.Id = Table.ReferenceToA
And it would possibly remove the repetitions.

Removing duplicate record text but keeping unique values

In our system, it shows each charge as a record, despite the account being the same.
Crystal reports image
How would I go about doing this?
Also, is there a way to show it like this even though they are all seperate records?
Option 2
You can solve this using sub reports.
In main report take distinct record and place the fields Account and city in detail section.
Now take sub report and place it after the first 2 columns in detail section but take care that you won't select the option distinct records that means you retrieve all records. In sub report place Charge type, charge fields

Grouping formula to account for two fields

Working with vehicle asset management and I am selecting data based on two statements:
({EQ_MAIN.PROCST_PROC_STATUS} in ["A", "AS", "AT"] and
{EQ_MAIN.DEPT_DEPT_CODE} like "P*" and
{EQ_MAIN.ASSET_TYPE} <> "COMPONENT")
or
({EQ_MAIN.PROCST_PROC_STATUS} in ["TA"] and
{EQ_MAIN.DEPT_TEMP_LOANED_TO} like "P*" and
{EQ_MAIN.ASSET_TYPE} <> "COMPONENT")
Basically, if the Equipment is in status A, AS, or AT and belongs to the departments that start with P, I want it to show on the report. However, the second part of the selection statement accounts for equipment that is temporarily loaned to another department (status TA). The selection statements seem to be working fine.
I have this data grouped by {EQ_MAIN.DEPT_DEPT_CODE}. But I want it to to include any temporarily loaned out equipment under the department group, if the equipment is on temp loan to said department. For example, Car A belongs to department K1234, but is on loan to department P5678. I want Car A to show up under the group for P5678 along with all the other vehicles that belong to P5678. Essentially, whether a piece of eq belongs to a specific department or is simply on loan to said specific department, I want to see them under the same group in Crystal. Thoughts?
I do not believe that a grouping formula is the solution for this scenario. The challenge is based in the recordset. Since there is only one LOANED_TO record per DEPT_CODE, you can go about this a couple of ways.
If this is an option, modify your query or view so that you generate all LOANED_TO records for each DEPT_CODE. This could be achieved by placing a subquery in your FROM clause if using SQL. Then, join your parent table EQ_MAIN to the subquery on a non-unique, general key. Since there is no one-to-one relationship in this scenario, you should get all LOANED_TO records for each DEPT_CODE. This will, however, bloat your recordset and mar performance.
Then, group the report first on {DEPT_CODE} and second on {LOANED_TO}. Use a suppression formula on the second group to hide any {LOANED_TO} Departments that do not match the parent group {DEPT_CODE}.
The more "traditional" Crystal approach is to group on {DEPT_CODE}. Then, add a sub report to a group section. Using the same datasource, move the second chunk of selection criteria (following the OR clause) to the sub report record selection. This will return all {LOANED_TO} records. Add a sub report link between the group {DEPT_CODE} and the sub report {LOANED_TO} dept. This will filter results to just those {LOANED_TO} records related to the main group.

Crystal Reports: Accessing printed records

I've been working on a report that uses subreports to print records.
The problem is: for the same information, there may be several records - i.e.:
There may be several records for the same product if those records differ in one single column. My goal here is to make a Record Selection Formula that says: "if that item is already shown, then don't show it once again."
I've tried to use (shared) variables for this, but can't seem to find the way, because of the evaluation time.
Selection formulas are already being used to apply some filtering criteria. The column that may differ between two ocurrences of the same record is not always the same, so using a simple Selection Formula is not likely to work...
Any suggestions?
Example:
I used the record selection to tell the report:
"Show me all the products according to these criteria (warehouse=parameter1 and category=parameter2 for example)".
But there may be more than one record for the same product of the same category and inside the same warehouse, if one or more fields are different (for example, different price, different lot)
I want not to display those repetitions.
Your approach is wrong... Record Selection Forumula is something that is applied at report level not on the row level or column level.
If you requirement is not to show the records that duplicates then you need to write the supress condition for those, As per your requirement apply supress condition to the rows or columns.

Show Report group even when no records selected

I'm trying to show employees at a company grouped by worked and still working (in vs2005 crystal reports).
The user can pass by parameter a list of companies they want to show.
Tables: VRP-COMPANY, VRP-COMPANY-OPPORTUNITY, VRP-OPPORTUNITY-PRODUCT
The record selection formula: {VRP-COMPANY.COMPANY company} in {?companies}
Grouping is done on: VRP-COMPANY.COMPANY company, then formula to decide its working or worked and then on productname.
Now when I run the report I only get to see the companies who have got entries in the VRP-COMPANY-OPPORTUNITY. I want to see the company name (group) even if there are no entries in the opportunity table. How to do this in Crystal Reports? I tried Left join between company and company-opportunity tabel but no effect.
I found the problem. Left join was correct but I had an additional select formula (on opportunity status to be closed-won. Therefore it let out the record. The record can also be null when there are no opportunities.
Should the question be deleted?