Grouping formula to account for two fields - crystal-reports

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.

Related

Filemaker: display related records based on date

I have 3 tables,
Table 1:
Client
Table 2:
Followups
Table 3:
Referrals
It's a one to many relationship where one client can have multiple followup or referrals.
How do I display the Followups and Referrals between 2 dates?
I have a summary field which counts the total of each followup and referrals but they show me all the count rather than in between a given date
In your relationship graph make a new table occurance that restricts the related set based on a date range. Here is an example image. You can make "date one" and "date two" globals so that they are not stored, and operate across all records. Base your sum / count calcuations based on this relationship.
Otherwise you can use a sub-summary on your layout in list view, and place the Summary fields in the sub summary. The summary field will show the sum for that sub section.
Another option is to place the summary field inside a one-row portal and filter the portal to show only records within the desired range.
This requires much less resources than adding filtered relationships - but it can be slow if you have too many related records.

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.

Crystal Reports Record Filtering using and

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.

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

Crystal Reports sort by subreport

So I have a series of orders that come in everyday. We add them to a database and then use Crystal Reports make packing sheets of these orders. We have two tables one for order information(name, address, order number, etc) and one for the items. In Crystal Report we use the order for the report and then do a subreport with all the item associated with order number. Now I have been given the requirement that we need to all the orders sorted by the first item's item number. How do I sort a report by a field in a subreport?
First of all, you can accomplish this report w/o a subreport. The report would be grouped by order # w/ the order fields in the group header. The Details section would contain the order-items.
In any case (my approach or yours), if you just need to sort the order-items by item number, simply reference that field in the Record Sort Expert.
If you need to sort the orders by each order's order-items[0] (the first item in the list), you'll need to create a SQL Expression that returns the item #. If you add a group on the SQL Expression field, then make that the top-level group (G1), the report will group first by the SQL Expression, then by the Order #. The SQL Expression should resemble:
(
//this will select the numerically-smallest item# for a given order#
SELECT min(item #)
FROM order-items
//correlate to 'main' query
WHERE order#=order.order#
)
If you need more complex rules for 'first item #' (whatever that means), you need to include it in the SQL Expression.