I have three global variables. two loose their value when they hit a footer, but the other one does not, and I do not understand why.
1 group header
2 group header (all 3 globals reset)
3 group header
detail (not displayed)
3 group footer (values on globals set and displayed- see the functions below)
2 group footer (attempt to sum all variables together)
1 group footer
when I attempt to sum the globals on 2 group footer, varCccCount is at zero and varFishCsvcCount is at zero, but Varothercount retains it's value.
Any suggestions?
global numbervar varCccCount;
whileprintingrecords;
if left({v_EIS_EECoreCourseReq.COURSEID_I},3)="CCC" then
// this is a CCC course and I want to count it
if isnull (Maximum ({HR2TRA04.DATE1}, {v_EIS_EECoreCourseReq.COURSEID_I}))
then
// this CCC course has never been taken
varCccCount:=varCccCount
else
// has this CCC course expired by the cut off date of the report?
if {#Expires}<{?Cut-off Date} then varCccCount:=varCccCount else
varCccCount:=varCccCount+1
// this is not a ccc course, and I do not want to increase the CCC count
else varCccCount:=varCccCount
global numbervar varFishCsvcCount;
whileprintingrecords;
if {v_EIS_EECoreCourseReq.COURSEID_I}='FISH' OR {v_EIS_EECoreCourseReq.COURSEID_I}='CSVC' then
// this is a FISH or CSVC course and I want to count it
if isnull (Maximum ({HR2TRA04.DATE1}, {v_EIS_EECoreCourseReq.COURSEID_I}))
then
// this CCC course has never been taken. do not increase
varFishCsvcCount:=varFishCsvcCount
else
// has this CCC course expired by the cut off date of the report?
if {#Expires}<{?Cut-off Date} then varFishCsvcCount:=varFishCsvcCount else
varFishCsvcCount:=varFishCsvcCount+1
// this is not a ccc course, and I do not want to increase the CCC count
else varFishCsvcCount:=varFishCsvcCount
global numbervar varOtherCount;
whileprintingrecords;
if not({v_EIS_EECoreCourseReq.COURSEID_I} in ['CCC1','CCC2','CCC3','FISH','CSVC']) Then
// This is NOT a course we are already counting somewhere else, so lets take a look at it
if isnull (Maximum ({HR2TRA04.DATE1}, {v_EIS_EECoreCourseReq.COURSEID_I})) then
// this course has never been taken
varOtherCount:=varOtherCount
else
// has this course expired by the cut off date of the report?
if {#Expires}<{?Cut-off Date} then varOtherCount:=varOtherCount else
varOtherCount:=varOtherCount+1
// This is one of the courses we are already counting in another variable. lets not count it
else varOtherCount:=varOtherCount
Related
I want to suppress a group if a field does not change within that group. Here is a screenshot of my example data (the two red-boxed fields showing the groups that have the unchanging field):
As you can see the two groups, reservation_number 10002 and 10014, should be suppressed as their amount field does not change.
Ideally the above screenshot should become this:
Please note that there can be more than two amount rows in a group.
Follow below process
Create a formula #Initialize and write below code and place in group header
Shared numbervar counter;
counter:=0
Create one more formula count and write below code and place in detail where you have data rows
Shared numbervar counter;
if PreviousIsNull(amount)
then counter:=counter+0
else if previous(amount) = amount
then counter:=counter+0
else if next(amount) = amount
then counter:=counter+0
else counter:=counter+1
Create one more formula result and place in groupfooter
Shared numbervar counter;
Shared Numbervar counter1:=0;
counter1:=counter;
counter
Go to section expert and supress and write below condition:
EvaluateAfter({result}) ;
Shared numbervar counter;
if counter = 0
then
true
else false
Use below formula for supress of header:
EvaluateAfter({result});
Shared Numbervar counter1;
if counter1 = 0
then
true
else false
Let me know if this works else will suggest other way
How can I indicate multiple records with the same Invoice number, but a different Sales Person ID? Our commissions can be split into multiple Salespeople, so there can be two different Salespeople per an invoice.
For example:
Grouped by: Sales Person ID (No Changing this option)
These records are in the Group Footer.
Sales Person ID: Invoice: Invoice Amt: Commissions: (Indicator)
4433 R100 20,000 3,025 * More than one record on the same invoice with a different sales person
4450 R096 1,987 320
4599 R100 20,000 3,025 * More than one record on the same invoice with a different sales person
4615 R148 560 75
4777 R122 2,574 356
If your report has less than 1000 invoices, you may try something like this.
This will return true when a second ocurrence of the invoice shows up. Then you can make something like set the row background do red.
Global NumberVar Array invoices;
numbervar nextIndex := count(invoices) + 1;
if nextIndex <= 1000 and not ({Result.InvoiceNumber} in invoices) then (
redim invoices [nextIndex];
invoices[nextIndex] := {Result.InvoiceNumber};
true;
)
else false;
If you want to detect the first occurrence, you will need something more sophisticated.
I think a SQL Expression Field would be a good way to achieve the result you want. You already have an InvoiceNo in each row of data. You just need a SQL Expression Field that uses that INvoiceNo to execute a query to count the number of salespersons who get a commission.
Something along the lines of:
(
Select Count(Sales_Person_Id)
From [Table]
Where [Table].InvoiceNo = InvoiceNo
)
This will return an integer value that represents the number of salespersons who are associated with one invoice. You can either drop the SQL Expression Field in your Indicator column, or write some other formula to do something special.
I have a bunch of data in groups in Crystal Reports. There's a status field, and for each group I want to display the number of occurrences of a specific status in the group footer.
Example:
==============
Group 1 Status
==============
Foo
Bar
Foo
Foo
Foo
Foo
Foo
Bar
Bar
Foo
----Number of occurrences of "Bar" displayed here-----
==============
Group 2 Status
==============
Bar
Bar
Foo
----Number of occurrences of "Bar" displayed here-----
How can I accomplish this?
This kind of accumulator can be handled with three formulas. It's also possible to do this in SQL in many scenarios.
{#ResetBarCount} // Place this formula in the group header and hide it
global numbervar bar_count = 0;
{#IncrementBarCount} // Place this formula in group body and hide it
global numbervar bar_count;
if <DATABASE_COLUMN> = "Bar" then bar_count := bar_count + 1
{#BarCount} // Place this formula where you want to see your result
global numbervar bar_count;
My Crystal syntax maybe a little rusty so apologies if you have to tweak it.
I was able to accomplish this by creating a new formula field:
IF {Status} = "Bar" THEN 1 ELSE 0
Then inserting a summary of the group sum of the formula field and suppressing it so all you see is the summary, which gives you an exact count of the number of "Bars" in each group.
I have a crystal report, which shows different fruits data on the basis of Fruit Name Group.
I am attaching a screen shot which tells the clear requirement, I want to group same type of fruits merge all into one rows and sum of their values as well.
I need help, can someone suggest a better idea?
1) Add a Formula Field
This formula field, should return
- real FruitName for the cases you don't want to group,
- a fake FruitName for the rows you want to group together.
Something like this (drag'n drop fields into Formula editor):
if {commandname.FruitName} <> 'Orange' AND FruitName <> 'Lemon'
AND FruitName <> 'Grape Friut' then {commandname.FruitName}
else 'Orange, Lemon, Grape Friut'
2) use Group Expert to create a Group based on the new Formula Field
3) suppress details and show in Group Header or Group Footer Totals for each field
I am not able to understand completely you problem.. but try below solution: If it is useful use it else discard
Concatenate Fruit Names: Create one formula #Fruit
Local StringVar orange;
Local StringVar Lemon;
Local StringVar Grape;
if <<databasefield.fruitname>>="Orange"
then orange:=<<databasefield.fruitname>>
else if <<databasefield.fruitname>>="Lemon"
then Lemon:=<<databasefield.fruitname>>
else if <<databasefield.fruitname>>="Grape"
then Grape:=<<databasefield.fruitname>>;
orange+Lemon+Grape;
Summing the values: Create one formula #Weight
Local NumberVar orange;
Local NumberVar Lemon;
Local NumberVar Grape;
if <<databasefield.fruitname>>="Orange"
then orange:=<<databasefield.Weight>>
else if <<databasefield.fruitname>>="Lemon"
then Lemon:=<<databasefield.Weight>>
else if <<databasefield.fruitname>>="Grape"
then Grape:=<<databasefield.Weight>>;
orange+Lemon+Grape;
Edit:------------------------------------------------------------------------------------
you need to have grouping something like below.
Fruit name Fruit Type
Orange a
Grape a
peach b
apples c
now when you group by fruit type and apply the formula I have provided then you can get desired results
I have done with other way, calculated these fruits values as a separate row, sum up all the values and then applying union , In union I have concatenated the fruit names using COALESCE function
I have a report in which I'm trying to sum a summary on one group to another group. Ex:
group 1: 75 <- sum of the maximums
group 2: 50 <- max of the group
line 1: 50
line 2: 40
line 3: 10
group 2: 25 <- max of the group
line 1: 10
line 2: 2
line 3: 25
I've tried using a running total, but can't seem to get that right. I've also tried to put the maximum part into a formula, but Crystal still won't summarize it.
If you absolutely have to have the value in the Group1 Header then I think your only option will be a SQL Expression.
The Group1 Footer would be much easier. The gist is that you can simply keep track of the sum of the maxes with a variable.
//Place this formula in the Group1 Header
whileprintingrecords;
numbervar g1sum := 0;
//Place this formula in the Group2 Footer
whileprintingrecords;
numbervar g1sum;
g1sum := g1sum + maximum({table.value},{table.group2_field})
//Place this formula in the Group1 Footer
whileprintingrecords;
numbervar g1sum;