sum field in crystal report - crystal-reports

I have two text fields in crystal report, textA and textB.
What if I wanted through the formula editor (not via c# code) set a third field called textTot = textA + textB.
What is the correct crystal report syntax?
Thanks a lot.

The simplist formula is: ToNumber({TableName.TextA}) + ToNumber({TableName.TextB}).
However, it would be a good idea to first test whether the data is numeric (to avoid a runtime error):
Local NumberVar numericA;
Local NumberVar numericB;
If IsNumeric(Trim({textA}))
Then numericA = ToNumber(Trim({textA}))
Else numericA = 0;
If IsNumeric(Trim({textB}))
Then numericB = ToNumber(Trim({textB}))
Else numericB = 0;
numericA + numericB;

Related

Numberfield to time in Crystal 10

I'm new to crystal so please excuse me if this is a stupid question. I've got a database field in Sage ERP which is the time, stored as a GMT time, the field type is number. So for example the data in the filed will be 8461110 (08:46) or 13021054 (13:02). Now in crystal I need to convert this field to time because I need to select data between 2 times. I've struggled with this yesterday for the whole time, but no luck.
I've created a formula field with the following code but the result I get is 00:00:00
Local NumberVar TheHour;
Local NumberVar TheMin;
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheHour = ToNumber(Left(ToText({ICHIST.AUDTTIME}),2))
else
TheHour = ToNumber(Left(ToText({ICHIST.AUDTTIME}),1));
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheMin = ToNumber(Mid(ToText({ICHIST.AUDTTIME}),3,2))
else
TheMin = ToNumber(Mid(ToText({ICHIST.AUDTTIME}),2,2));
Time(TheHour,TheMin,00);
What am I doing wrong, why is the result 00:00:00?
Problem is you are missing this :. In crysal reports whenever you want to assign a value to a variable syntax would be :=. So your formula will be
Local NumberVar TheHour;
Local NumberVar TheMin;
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheHour := ToNumber(Left(ToText({ICHIST.AUDTTIME}),2))
else
TheHour := ToNumber(Left(ToText({ICHIST.AUDTTIME}),1));
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheMin := ToNumber(Mid(ToText({ICHIST.AUDTTIME}),3,2))
else
TheMin := ToNumber(Mid(ToText({ICHIST.AUDTTIME}),2,2));
Time(TheHour,TheMin,00);

Average data which comes out of a Crystal Report formula

I have a formula in my Group Header which looks like the following:
if count({Removals.rpid},{Removals.r-ixservice}) <> 0 then
( sum ({#SIT - Count},{Removals.r-ixservice}) / count({Removals.rpid},{Removals.r-ixservice}) * 100)
else 0;
This works perfectly in that it spits out a % number based on the fields above. However, in the Report Footer I would like to average all the data generated by the above formula and spit it out so that if in the report this formula had been on 3 lines saying 90-80-70, then in the footer it would say 70.
I tried using Average({#Formulaname})but Crystal just says "This field cannot be summarized".
Thanks.
Its already a summarized formula so you can't summarize it again..suggested option would be use arrays and summarize.
Try this
Use the formula in group header and supress
Shared Numbervar array store;
if count({Removals.rpid},{Removals.r-ixservice}) <> 0 then
store:=store+( sum ({#SIT - Count},{Removals.r-ixservice}) / count({Removals.rpid},{Removals.r-ixservice}) * 100)
else store:=store+0;
1
Now in report footer
Shared Numbervar Array store;
Local Numbervar i;
Local numbervar final;
For i:=1 to Ubound(store) do
(
final:=final+store[i];
);
Final/Ubound(store);

Crystal Reports If Any Record Meets Condition, Exit Formula

I wish to create a formula that will read each record, and if a certain condition is met then the formula will stop reading records and return a specific label. I have tried the following code and the correct result is displayed at the detail level but not the footer. It appears the "exit for" isn't really working. Thanks for your help!
Current Code (I have placed in the report footer):
shared stringvar label := "";
local numbervar i;
for i := 1 to {#Count_Records} do
(
if ({report_data.return_code}[i] = "defective-exchange"
or {report_data.return_code}[i] = "defective") then
label := "Defective-Exchange Only";
exit for;
);
if label = "" then
label:="Pickup Credit Memo";
label;
To eliminate data, use a record-selection formula:
{report_data.return_code} = "defective-exchange" or {report_data.return_code} = "defective"
To format data, use a formula field:
// {#Return Code}
if {report_data.return_code} = "defective-exchange" or {report_data.return_code} = "defective" then
"Defective-Exchange Only"
else if {report_data.return_code} = "" then
"Pickup Credit Memo"
else
"something else"

Crystal Report Counting

My question is similar to the link.
Crystal Reports - Count Formula
The answer only works when the certain status type is giving to you.
Now I am wondering that what if the status type is not giving to you (You dont know what's inside this filed first), and the type of the status can be varied based what's in {statustype} field.
And I want to be able to list all distinct status type and calculate it's total appearance in the report.
Well its easy if you see it my way, I read that thread which you referenced.
Make different Formulas for all the status types that you may know of, I am pretty sure that they will be maximum 4 or 5. Make formula like
localvar int x;
if(statustype = 'Accepted')
(
x = x++;
)
x;
Or you can put all the formulas to one, using the same if clause but changing the display string, make sure that its a summary field or is placed at the report footer.
localvar int accept;
localvar int reject;
localvar int Pending;
if(statustype = 'Accepted')
(
accept= accept++;
)
else if
(
reject = reject ++;
)
else if
(
Pending = Pending++;
);
"Accepted "+ accept + " Rejected " + reject + " Pending "+ Pending;
Hope this helps,
I figured out that a easy way that we can create a placeholder in main report for subreport. And we can make the manipulation in the subreport

Crystal Reports/FormatEditor/Display String formula: How to format data

I want to specify a formula for the display string property of an object on my report, however I want to use it to format the data that would otherwise show up if I were not using this formula. Is there a keyword or anything I can reference within the formula that represents what would normally be displayed?
You might need to create a formula field and reference your database field within it:
for summarized fields, I use min(#cellVal) in the crosstab:
dim cVal as number
cval = {vw_rpt_waitlist.CountOfRecipientID}
if cval < 0 then
formula = " "
elseif cval = 0 then
formula = ""
elseif cval < 5 then
formula = "< 5"
else
formula = cstr(cval,0,",")
end if
and in the rows list, to modify the sorting:
if {vw_rpt_waitlist.SupportCode} < 100 then
formula = {vw_rpt_waitlist.description}
else
formula = "z" + totext({vw_rpt_waitlist.SupportCode}) + {vw_rpt_waitlist.description}
end if
It doesn't seem this is possible as far as I've been able to tell.