Groups being printed twice after page break - crystal-reports

I have made a report that shows transactions in a certain time period for certain products.
To simplify it; its based off 3 tables: Transaction, Product and Customer. Transaction joins to Product and Customer by keys ProductID and CustomerID respectively. The product can be used by several customers though, so there is no join between customer and product.
The report is structured as below:
Report Header:
-Group Header 1 - CustomerID (prints name, id etc)
--Group Header 2a - Product Code (prints name, description..)
--Group Header 2b - sub report GetOpeningBalance
---Group Header 3 - Transaction Date
----Details (nothing printed)
---Group Footer 3 - Prints transaction date, details, new balance
--Group Footer 2 - Prints Product closing balance (opening - transactions).
-Group Footer 1 - Prints nothing.
Report Footer - prints nothing.
The sub report GetOpeningBalance calls a stored prodedure and returns a number in a shared variable corresponding to the opening balance. This is then incremented/decremented by each transaction and the closing balance is displayed at the end.
Now the selection formula is based on: Customer, Product and Date Range (to/from). Customer and Product can be discrete, range or discrete + range values.
This worked fine; it showed product transactions which occured in the range given and displayed numbers. The customer however wanted it to show all products; even if no transactions had happened in that time period. For example they had stock; but there were no intakes/outtakes so the opening and closing balance are equal.
So to solve this; I removed the date range parameter in the selection criteria (so it returns all transactions for the product) and have then supressed any detail lines that fall outside of the wanted date range. I have modified the running total formulas accordingly so they only include the "shown" transactions.
Now I am experiencing strange behaviour. Complete groups can be duplicated on the next page.. Say products 1-9 are printed on page 1, you would expect page 2 to start with product 10 and so on. However products 1-9 are printed; but then products 8 AND 9 are printed again at the start of page two . It prints the full section including the correct totals.
This behaviour is not consistent; it wont do it on every page or for every date range/product selection.
I have attempted ticking/unticking keep together in the Section Expert and the Group Expert. I have also tried removing some extra groups and details to try narrow it down to no avail.
Are there any options or settings that may be causing these groups to be reprinted?
I would usually use a subreport for the details section in these kind of problems; however because there is no direct join between product and customer it makes it impossible.

I had some free time to play with this today.
I found that switching the Group Header 2a with 2b; so that the subreport is before the product details header will stop this behaviour happening.
Now to test, test, test!

Related

Suppress records in grouped section between first two and last records in Crystal Reports

First, I am using Crystal Reports 2011. I need to suppress records in a group that fall between the first two records and the last record. In other words I only want to see record number 1 and 2 and the last record. I can easily suppress records that are not the first two, but getting the last record to not be suppressed has me at a standstill. I am creating a report where we want to only show the first, last and next-to-last time we purchased items. Some items have been purchased many, many times. I have the report grouped by part number, then all the dates we purchased the part (and other data) are in the group details. I have tried using a running total count, where I simply suppress details that are not 1 or 2, but the last record count varies depending on how many times we have purchased the item, so I don't know what the last count number will be for each group to use it in the suppress formula. I have also tried with declaring a variable and increment the variable for each record, but end up with the same problem as using running total count. Anyone have a suggestion?
To clarify my question a little further, I am sorting the group by date, most recent date first. So record count 1 is the last time we purchased and record count 2 is the next-to-last time we purchased. So by using record count I can suppress records that are not 1 or 2. The problem comes when trying to figure out how to not suppress the last record (which is the first time we purchased). Below is a link to a pic of what my report looks like with nothing suppressed. For this part I would want to suppress all records except 1, 2 and 5. But again, the last count number will change per part number depending on how may times we have purchased the part.
Help is greatly appreciated!!!!
Report cropped image
Using Crystal syntax you can test on OnLastRecord which returns true if you are on the last record or false if not. Simply suppress accordingly.
EDIT:
As pointed out by jmears, the above won't work for multiple groups of differing products.
Instead you can add a running total field to count each record within the group, reset on change of group. Then suppress the details based on the running total not being 1 or 2 (for the first two records) and not equal to the total count of records for the group.
Here's an example suppression formula, where {#rt} is the running total count of records. It uses the Count function to return the total count for the group
not({#rt} = 1 or {#rt} = 2 or {#rt} = Count ({fieldToCount}, {GroupField}))

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.

Remove duplicate results within one group Crystal reports

My SQL Stored Procedure returns following result:
ID District Decision
-----------------------
17 First Approved
17 First Partially approved
17 First Pending
17 Second Approved
17 Second Partially approved
17 Second Pending
The same was generated in my Crystal Reports. District and Decision columns have no any relationship. Both of them only related to ID (requestId). I'm getting duplicated results for each District as the result of joining 3 tables.
So far I was able to group records by ID and suppress duplicated rows. After doing so I've got following in my Report:
ID District Decision
-----------------------
17 First Approved
Partially approved
Pending
Second Approved
Partially approved
Pending
So far so good, but what I eventually want is to get is something like follows:
ID District Decision
----------------------
17 First Approved
Second Partially approved
Pending
I want all blank spaces to be removed (which is left after suppressing duplicated) and leave only distinct records within ID group.
I want to do everything in Crystal Reports, that's why i'm excluding work around in the SQL server
If editing the SQL isn't an option, you're on the right track. In short you'll want to:
Write a formula (#YourFormula) that evaluates True if the previous record has the same ID and District. (Hint: use the PREVIOUS() function.)
Format each field in your Details section such that the Suppression formula is set to #YourFormula.
In the Section Editor for Details, check "Suppress Blank Section".
This all hinges on whether or not your records are grouped correctly. If they sometimes appear out of order, you might need to edit your current SQL after all.

Crystal Reports XI - Suppress group header based on suppression status of sub-groups

I have a rather simple problem that I haven't managed to workout for myself despite many hours of searching the web.
I have a report containing timestamped data from a few thousand devices (loggers), to present the data in a sensible manner, I set up two groups in the report; Loggers and Timestamp so the data first grouped by logger id and then by timestamp which is working fine
Group 1 Logger 1
Group 2 Timestamp 01/08/2012
Data...
Data...
Data...
Group 2 Timestamp 02/08/2012
Data...
Data...
Group 1 Logger 2
Group 2 Timestamp 01/08/2012
Data...
Data...
Data...
Now the data (detail) fields are hidden from the user and I only want to display the header for group-2 if there are 4 or more records in each group-2. To achieve this I have used the following suppression formula on group-2
Count ({GMAC_spDg2Report;1.tTimeStamp}, {GMAC_spDg2Report;1.tTimeStamp}, "daily") < 4
The trick is that there are certain level 1 groups where all group-2 headers are suppressed and where this is the case, I want to hide the group-1 header as well.
Using the same suppression formula as group-2 in group 1 did not yield the desired result. I have also tried to use a running total (called {#Count Unsupressed Days}) in the group-1 footer with a distinct count and the formula below being reset on each group-1
Count ({GMAC_spDg2Report;1.strLogger}, {GMAC_spDg2Report;1.tTimeStamp}, "daily") > 4
The running total works perfectly, returning a 1 in group-1 footer if the group has sub groups that are not suppressed and 0 if all group-2 headers are suppressed.
So here is the CHALLENGE, I cannot seem to apply a suppression rule in the header of group-1 using the output from the running total.
To demonstrate the problem I created a formula field containing only the output from the running total and placed this in the group-1 header.
The results are confusing to say the least... the formula field does not show the same value as the running total and hence the suppression rule is not working.
I hope this makes some kind of sense... I feel like I have tried everything
I don't have a definite solution, but using a formula field starting with
WhilePrintingRecords;
...
the formula will be processed after all records are read, and therefore you will be able to use it in section headers with correct result.
Now there is the problem of finding a formula logic that will be of use for you, but perhaps this first step can help you in the right direction.
I had a similar problem once. As I remember, the trick was to check Suppress blank section in every detail section and checking some similar sounding option Suppress blank group (?) in group header section.
Sorry I can't give you the exact name, it's long ago and I used the German version. I know it's possible without formulas, though.
I take it you don't use sub reports. If you do, note that the trick only works if the sub report has the option Suppress empty report (?) checked along with what I wrote above.

Crystal reports - Group total

I have a report that I've written and I understand how to create running totals and such, but need help creating a custom evaluation formula.
I have two levels of groups, first group is based upon a certain user, the next group is based upon transactions that user has been involved in. I have details hidden, and am only interested in the totals for a particular activity. This is working great, and totals are working properly but the problem is, each activity has a 'line number', which essentially can be the same as another activity (ie: two activities can have lines 1, 2, 3 contained within), so doing a distinctive total based upon a set of data isn't accurate because I only want it to be distinct based upon each individual recordset, and not globally.
The example is below... if I do a count on each record for this dataset, it comes out to 18 because there are duplicate line numbers on each... but if I do distinct, it only comes to 9 because of duplicate line numbers across multiple actives.
I guess what I need to know is how I can take the totals per detail group, and have them total up in my second footer properly. I assume it's going to take me compiling together a string including the activity number and line number, and then comparing them?
Here is an example of the data contained within the total groupings:
I figured this out on my own... turned out it was pretty simple. I converted my numeric values to text, and included a copy of the transaction id and the line id as my test value, and did distinct on that... Sometimes it just helps not staring the problem down.