Crystal Formula to multiply Time by Cost - crystal-reports

I need a formula that would multiply {table.time} * {table.cost}.
This is what I tried :
tonumber ({#timeformat}) * {Table.cost}
Formula for {#timeformat}
whileprintingrecords;
numberVar hrs;
numberVar min;
stringVar hhmm;
hrs := Remainder(Truncate({table.time}/60),60);
min := Remainder({table.time},60);
hhmm := totext(hrs,"00") + ":" + totext(min,"00");
hhmm
When I simply do that I get a string error from Crystal when I run the report.
String is non-numeric.
Any help is greatly appreciated.
Thanks

Your function {#timeformat} is producing strings that look like 02:30. They're useful for readability, but they're not numeric, nor can you multiply them.
Instead, try:
{table.time} * {table.cost}

Related

How to convert numeric time to HH:MM

I have a time field which displays as the following:
9:50:03 is 95003
14:53:44 is 145344
So when it's a single digit hour, the value is only 5 characters vs double digit hour is 6 characters.
I need to convert 95003 to 9:50 and 145344 to to 14:53 following this formula for any time.
If I were to do this in any language I would parse the data by 2 digits and add a : to each part. I would need to know what language to help you though. Or if it does not matter please emphasize.
This is very general without seeing your formula, but this is how I would go by doing it.
EDIT:
NumberVar dur := Sum ({#elapsed});
NumberVar hrs;
NumberVar min;
NumberVar sec;
StringVar hhmmss;
hrs := Truncate(Truncate(dur/60)/60);
min := Remainder(Truncate(dur/60),60);
sec :=Remainder(dur,60);
hhmmss :=totext(hrs,"00")+":"+totext(min,"00")+":"+totext(sec,"00");
Second Try
datediff("s",datetime(date({table.occdate}),{#enroutetimetotime}),datetime(date({table.inservicedate}),{#inservicetimetotime}))
OR - Probably your best shot
numbervar ntt := {YourTable.NumberField};
stringvar nttx := totext(ntt,"000000");
time(val(left(nttx,2)),val(mid(nttx,3,2)),val(right(nttx,2)))

Crystal Reports 13 Standard Deviation with formula fields

I've been working on a report made by someone else which uses the StDev function. I thought it would be simple enough, but the data can contain multiple values for each record, so there are if statements used to determine which value to take from each record. I've exported a table to Excel which contains one value per record (the one that should be used in the StDev), and then calculated the SD there to provide a check.
The report and Excel are giving me very different values :(
So, I'm going back to the report and using some additional formula fields to calculate the SD longhand to act as a kind of deciding vote (fingers crossed it doesn't produce a third set of values...).
I've worked out the syntax errors, but am still getting a run-time error - "Division by zero" which then highlights the section of code indicated below...
My formula fields are:
{#StDevArrayPopulate} - in the details section
NumberVar Array varStDevArray;
NumberVar varStDevArrayCount;
varStDevArray [varStDevArrayCount] := {ValueToSummarise};
varStDevArrayCount := varStDevArrayCount + 1;
{#StDevArrayCalculate} - in the group footer
NumberVar Array varStDevArray;
NumberVar varCounter :=1;
NumberVar varMean := 0;
NumberVar varStDev := 0;
NumberVar varStDevArrayCount;
// START OF MEAN
// Sum of all of the values in the array
for varCounter:= 1 to varStDevArrayCount step 1 do
(
varMean := varMean + varStDevArray [varStDevArrayCount];
);
// Divide by the total number of values in the array
varMean := varMean / varStDevArrayCount; // !! This is the line that highlights after the error message !!
// END OF MEAN
// START OF STANDARD DEVIATION
// Subtract the mean from each value in the array and square the result
for varCounter := 1 to varStDevArrayCount step 1 do
(
varStDevArray[varStDevArrayCount] := (varStDevArray [varStDevArrayCount] - varMean) * (varStDevArray [varStDevArrayCount] - varMean);
);
// Sum of all of the values in the array
for varCounter:= 1 to varStDevArrayCount step 1 do
(
varStDev := varStDev + varStDevArray [varStDevArrayCount];
);
// Divide by the total number of values in the array
varStDev := varStDev / varStDevArrayCount;
// Square root of mean of differences
varStDev := Sqr(varStDev)
// END OF STANDARD DEVIATION
{#StDevArrayCalculate} - in the group footer
NumberVar varMean;
NumberVar varStDev;
"The mean is " & varMean & ", and the standard deviation is " & varStDev & "."
I've tried using a Running Total field but that was giving errors as it need to be count the first record before the Populate formula field ran. I've also tried adding a fourth field to the header, which initialises the varStDevArrayCount as 1.
Does anyone have any suggestions?
Looks like there are no detail records hence you are getting zero in array... I don't think initializing with 1 will make any difference instead make a small change like below and check.
if varStDevArrayCount=0
then
varMean :=varMean
else
varMean := varMean / varStDevArrayCount;
I would advice you to just check records in detail and then debug

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 report dynamic formula name

Here is what I have. I have 15 unique formulas named Week1, Week2, ... Week15. I would like to be able to take a parameter name, MYCount, and use that to loop through the records and sum them. So if MyCount is equal to 3, the loop would sum Week1 + Week2 + Week3. I know how to create a loop, but I cannot figure out how to build the formula name dynamically. Here is what I have so far: (I am using Crystal Xi)
Whileprintingrecords;
local NumberVar i := {?MyCount}
For i := 1 To (MyCount-1) Do (
i = {#Week & "i"} + i
);
x
I think you may be over complicating. Why not just do:
Local numbervar x := 0;
If param > 0 then
X := x + week1;
If param > 1 then
X := x + week;
And so on...
X;
I don't exactly what you are trying to do, but you may want to consider another approach.
Create a formula that will segment a field based on a date field's week number:
//{#amount}
// adjust firstDayOfWeek and firstDayOfYear parameters to match your organization's
// definition of a week
If DatePart("ww", {table.dateField})<={?Week} Then
{table.amount}
Insert a summarized field on the formula field.
If you are using your #Weekn formula fields so that you can summarise by date across the page, then have you considered using Crystal's Crosstab functionality instead?

Crystal Report formula field formula that pulls a date out of a string?

I need to extract a date out of a invoice number and subtract one month from the month.
For example if a invoice number is I2011101002683 I need to pull out the 2011, four numbers starting a position 1, and then the 10, two numbers starting a position 5.
and display the date in a 2011/09 format. Thanks in advance.
One way:
numbervar year_start := 2;
numbervar year_len := 4;
numbervar month_start := year_start + year_len;
numbervar month_len:= 2;
mid({Command.InvoiceNumber},year_start,year_len) + "/" +
mid({Command.InvoiceNumber},month_start,month_len);
Create a formula field to extract the date:
//{#invoice_date}
//I|2011|10|1002683 --> Date(2011, 10, 1)
Date(ToNumber({Command.InvoiceNumber}[2 To 5]), ToNumber({Command.InvoiceNumber}[6 to 7]), 1)
Add the resulting formula to the canvas; format it as desired.