Include formula field in cross tab - crystal-reports

Hi i have a long formula field which I would like to include as the cross tab report summary field. However after I define the formula field I don't see it in my crosstab screen. How to include it ?
Here is my formula field
WhilePrintingRecords;
numberVar rt;
numberVar layMdp;
numberVar totMdp;
rt=Round(({Command.GENGNPIAMT}/{Command.TOTALGNP})*100,2);
layMdp:={Command.GENPREMMDP};
totMdp:=(layMdp)*Truncate((rt/100),4);
Also if I place this formula field inside details section, it shows a zero. Why is it not calculating anything ? I like it to calculate values as per each cross-tab column.

You're setting the variables but the formula itself is not returning anything. If you want to return the value of totMdp, just add it after the last line:
WhilePrintingRecords;
numberVar rt;
numberVar layMdp;
numberVar totMdp;
rt=Round(({Command.GENGNPIAMT}/{Command.TOTALGNP})*100,2);
layMdp:={Command.GENPREMMDP};
totMdp:=(layMdp)*Truncate((rt/100),4);
totMdp

Related

How can I sum formula field in crystal report?

I want to show my Grand Total values by using a specific formula field.
Actually I want to sum formula fiel such as :
sum(#ClosingBalance)
But It gives a message
This Field Can not be summarize
How can I solve this problem ??
I solved my problem,
I explain below how can I solve this,
I need two other function to show grand total in my report footer, where I use formula field as my summarized field.
so, firstly I create a function name #Grouptotal by using below formula
Numbervar x:=x+{#ClosingBalance} And place it in my group footer
Then I create another formula name #GrandTotal and place it in my report footer
Numbervar x:={#Grouptotal}-{#ClosingBalance}
Finally I suppress the #Grouptotal Field , and get the result of #GrandTotal By using Formula Field.
Thanks a lot...
Yes, you can do this using variables.
Step 1: Create a Formula Field Named as Sum1:
Shared numberVar Sum1;
Sum1 := (Your Table Field) + Sum1;
Place this one in Details section and suppress it (Right Click Formula --> Format Field --> Common --> Suppress).
Step 2: Create another formula to display the result as PrintSum1:
Shared numberVar Sum1;
Sum1;
Place this formula in Group Footer and suppress it (Right Click Formula --> Format Field --> Common --> Suppress).
Step 3: Create another formula field:
Shared numberVar GrandTotal;
GrandTotal := GrandTotal + {#Sum1}
This way you can summarize a formula field. Place this one in group footer.
Step 4: Create one last formula as Clear:
Shared numberVar Sum1;
Sum1 := 0;
Place this formula in Group Header and suppress it. This is to clear the Sum1 value for every record or group.
Let me know if you have issues.

Summarizing Shared Variable in Crystal Reports

I have a formula that uses two shared numbers in it. I now need to sum this formula. If I use running total or sum functions, the formula does not show in the pick list.
The formula I need to sum is called "excel formula" and this is the calculation the formula is doing:
({#Shared Total Wt Lbs}*{#Shared Scrap})/100
The "usual way" of creating a sum or running total does not work for a formula that holds a variable .
To get a sum of it you'll need to use a third variable.
Place the following formula in detail-section to add up the values:
WhilePrintingRecords;
NumberVar SumOfExcelFormula;
SumOfExcelFormula := SumOfExcelFormula + {#excel formula}
Use the following formula to show the sum:
WhilePrintingRecords;
NumberVar SumOfExcelFormula;
To reset the sum on every group change, put the following code in a formula-field and place it on the group header:
WhilePrintingRecords;
NumberVar SumOfExcelFormula := 0;

Duplicates in sub-report

I have crystal report with a sub report in it. The sub report is displaying duplicates. To avoid that I used below formula.
{table.IDField} = previous({table.IDField})
Now, duplicates are removed but I have sum of the field in the footer. All the duplicate values are added to the sum. Is there a way that I can select distinct records in the sub report?
I followed below steps to solve this issue.
Created a group on the IDField
Moved all the fields from detail section to the above group header.
Suppressed the detail section.
Created the below formula and placed it in group header. I have supressed this because I didn't have to display this.
whileprintingrecords;
numbervar totalOfIDField := totalOfIDField + {IDField};
"";
Created a formula to display the above field (totalOfIDField).
whileprintingrecords;
numbervar taotalOfIDField;
This should be placed in the corresponding Group Footer.
Created a formula to reset the totalOfIDField each time group changes. Included this in the Main Group Header.
whileprintingrecords;
numbervar totalOfIDField := 0;

How to summarize a formula field in crystal reports?

How do I add a running total or summary field on a formula field in crystal reports?
// Sample Report
Serial No. Premium Commission Net (Premium-Commission)
-----------------------------------------------------------------------------
1. 10 4 6
2. 40 30 10
---------------------------------------------------------------------------
Grand Total 50 34 16
In sample report, Net (Premium-Commission) is a formula field which gets evaluated for each row? How do I add a grand total/summary field for my formula? It seems we can add a summary field to only Command fields.
Suppose Net (Premium-Commission) formula field name is {#Net}. Now you have to create another three formula fields.
Initializer: this formula filed will be placed in header section to reset all variables.
Increment: this formula field will be placed in detail section to summarize the value.
Total: this formula field will be placed in footer section to show total of {#Net}.
Code will be writen in formula fields as below.
{#Initializer}
WhilePrintingRecords;
Numbervar dSum :=0;
{#Increment}
WhilePrintingRecords;
Numbervar dSum; //Don't initialize zero
dSum:=dSum+{#Net}; //{#Net} formula field must be return numeric value
{#Total}
WhilePrintingRecords;
Numbervar dSum; //Don't initialize zero
dSum;
Place all formula fields in their appropriate section and suppress {#Initializer} and {#Increment} formula field.
If you are using any calculation then that is not possible but one workaround would be to sum the each row and reset it in header.
Create a formula #Intialize in that write below code:
Shared NumberVar count;
count:=0
In detail write below formula and place it after Net (Premium-Commission).
Shared NumberVar count;
Count:=count+<>
\
3. Now create one more formula #Display and place it in footer.
Shared NumberVar count;
count;

Crystal Reports - Selecting data in the first row to be used in a formula

I have a very basic report with no groups. The details consists of a number of numeric columns. I want to add a formula field which will use a field from the first row. Example:
(ColumnAFromCurrentRecord - ColumnBFromFirstRecord) / ColumnBFromFirstRecord
Can someone point me in the right direction?
1.
Create a formula named AssignFirstValue and define it like this:
WhilePrintingRecords;
Global StringVar strFirstValue := {MYDBNAME.MYSTRINGFIELD};
Put the AssignFirstValue formula in your Report Header and suppress it.
2.
Create a formula named PrintFirstValue and define it like this:
WhilePrintingRecords;
Global StringVar strFirstValue;
strFirstValue
Put the PrintFirstValue formula wherever you want to display the first value in your report.
you need to extact the column b from first record. try below solution.
Note: This is not a tested solution as I at present I don't have CR.
create below formula Count and place in detail section:
Local NumberVar a;
a:=a+1;
This will number the rows starting from 1 to the last row.
Now create one more formula StoreB:
Share NumberVar b;
if {#Count}=1
then b:=columnb
This will store the value of columnb in first record in variable b
Now use where you want:
EvaluateAfter(#StoreB)
Shared NumberVar b;
(ColumnAFromCurrentRecord - b) / b
Let me know how it goes.