Crystal Sub-report returning incorrect data - crystal-reports

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.

Related

Crystal reports - Can't filter on custom formula number field

Crystal reports don't let me use a custom count formula field to filter which transactions to show in a manager report.
I'm creating a Crystal report that team leaders are supposed to take out to see on how many occasions their employees have reported in sick. A record is only supposed to show if that person has reported in sick 6 or more times the last 12 months.
The report shows a record (a page) for each employee belonging to the managers organisational unit. Below the employee information is a subreport where I show the transactions from the salary/time system. Using select expert, I have filtered out the transactions that is supposed to show. I have then created a database field that count which day was 12 months back from today, and filtered so that only the transactions falling into this period shows.
My last problem is that I only want to show the record that has a minimum of 6 such transactions during the period. I created a formula field named #Antal ("amount" in Swedish) that simply counts the distinct number of dates in the "from"-date for the salary transactions I'm showing (since a change of law 2019-01-01 we needed to create a new transaction type, so some of the occasions after 2019 may have two transactions referring to one sick leave, thus I'm counting the first day of the period instead), DistinctCount ({P_LSTAT.P_SXXX06})
Now, the subreport has a new column with Antal (amount) that counts the amount of the desired salary transaction. I then try to use the selection formula to only show records where {#Antal} >= 6 but I get the following error:
This formula cannot be used because it must be evaluated later
Is there any other (better) way of doing this, or am I simply missing something?
For your selection based on {#Antal} >= 6 you need to use the group selection formula, not the record selection formula. Record selection is used to select records which meet the criteria before reading in the data. Group selection is used to filter out entire groups of records based on summarised values, after the records have been read in and the summaries calculated - which sounds like exactly what you need here.
The value of a Formula Field is out of scope when the Select Expert is evaluated.
There is no process for calculating the value of a Formula Field before it is printed within the section of the report it is placed. The Select Expert is evaluated prior to any section of the report being printed, so at this time all Formula Fields are effectively Nothing.

DSUM function in crystal reports?

I am trying to convert an old Microsoft Access report into Crystal reports. I have everything working perfectly except for this last small detail. The Access report uses a DSUM function within an if statement for one of the fields on the report.
After much searching, I've determined that CR doesn't have anything similar.
Here's basically what I'm dealing with.
I have a proposal report. In the details of the report I print the qty, description, and a couple of price fields.
The data looks like something this:
Proposalnum Partitem RolltoItem Unitprice
18611.............1.......... NULL........0.00
18611.............2......... NULL.......17225.92
18611............3............ 2............156.90
18611............4............. 2............482.05
What I need to do is when I print a specific part, I need to query through the rest of the records to find the parts that have a matching number in the rolltoitem field and add the unitprice to the part I'm printing.
So in this example when I print partitem #2, I need to add the 156.90 and the 482.05 from parts 3 and 4 to the 17225.92 so I print a total of 17864.87.
Is there any way to do this?
As far as i know, there is no such function.
But I would try this.
The general idea is: group the data by ProposalNum and use a subreport to select the "children rows" and sum the "children prices".
Details:
Create an empty group section by PartItem.
If you want to show only items where RoolToItem is null, use a suppress function for this case.
In the details section, put a subreport. The data source of the subreport would be the same of the main report.
Change subreport links to select data in subreport based on fields: PartItem in the main report = RolltoItem in the subreport.
Pass other fields to the subreport without select data: ProposalNum, PartItem, UnitPrice. I think you need to create parameters in the subreports before doing that - example: ParentProposalNum, ParentPartItem, ParentUnitPrice.
Create a new formula: ParentUnitPrice + Sum ({YourDataSource.UnitPrice})
Put the formula in the subreport footer a long with the other fields. Maybe: ParentProposalNum, ParentPartItem, formula.
It is a theoretical solution. I hope it points out to the right direction.
If you are trying to sum the Unitprice column for all items that have the same value in Rolltoitem, you could do this with a SQL Expression Field. The code would look something like this. My Where clause may need tweaked though since I'm not sure what your database structure looks like.
(
Select Sum("YourDataBaseTableName"."Unitprice")
From YourDataBaseTableName
Where "YourDataBaseTableName"."Rolltoitem" = *currentRolltoitemValue*
)
Syntax can also vary for SQL Expression Fields based upon what type of database you are using. The syntax I provided is fairly general, but should work on SQL Server.
EDIT: Adding example with explanation of how it works.
Here is one of my SQL Expression Fields from a crystal report that prints a Bill of Lading for shipped goods.
(
Select Sum("SHIPMENTS"."PALLET_COUNT")
From SHIPMENTS
Where "SHIPMENTS"."BOL_ID" = "BOL"."ID"
)
In my database the BOL table is the starting point. A single BOL can contain 1 or more SHIPMENTS, and a single SHIPMENTS can contain one or more PRODUCTS.
Top level grouping is on BOL.ID. The PALLET_COUNT is found once and only once on each SHIPMENTS. I also had a sorting requirement for the data in the details section that prevented me from using a Running Total Field.
This allows a BOL with 2 SHIPMENTS that contains a total of 3 products to look like this:
BOL.ID SHIPMENTS.ID SHIPMENTS.BOL_ID PALLET_COUNT PRODUCT.ID
1 10 1 2 XXX
1 9 1 1 YYY
1 10 1 2 ZZZ
The correct PALLET_COUNT for this BOL should be 3, since PRODUCTS XXX and ZZZ are in the same SHIPMENTS and the PALLET_COUNT is duplicated because of its relationship to the PRODUCTS.

Crystal Reports: Need to use a summary field as part of the Record Selection Formula

I have a fairly basic report that needs to show events with a total spend of >$200K OR event attendance >60ppl. The attendance portion is no problem, as it's a simple text field in the table. The expense spend is a field that has to be summed before it can be used, coming from a separate table with multiple entries per event. I have no problem doing this in a summary field dropped in the eventID header or even using a subreport and passing a shared variable to the main report. The problem I run into is that I cannot access this summary field in the report record selection to extract the either or records. Any idea how I can do this accurately?
Create a sql-expression field for total spending:
//{%total_spending}
(
SELECT sum(Amount)
FROM Meeting_Expenses
WHERE MeetingId=Meeting.Id
)
Use fields in record-selection formula:
{Meeting.actual_attendance}>60
AND {%total_spending}>200000

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.

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

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.