Crystal Reports 2016 Sum field on two groups - crystal-reports

I have a report that sums data and I am trying to modify it. I am trying to break out the totals by week by machine instead of one grand total by machine. Example of the calculations look like the following:
numberVar x := Sum ({WorkCntrSummary.Downtime_DurationInMinutes_Category0}, {WorkCntrSummary.Criteria_MachineID});
numberVar xh := Truncate(Round(x)/60);
numberVar xm := Round(x) mod 60;
if xh >= 1 then
ToText (xh, 0) + "h " + ToText (xm, 0) + "m"
else
ToText (xm, 0) + "m"
I am trying to change the 1st line where it is summing the field by MachineID. I want to sum it on the MachineID and also on a different group I added to the report which is a date field grouped by week. I am at a loss as to how to change that sum to add the date field by week to it. I tried changing it to the following, which doesn't do anything with grouping by week.
numberVar x := Sum ({WorkCntrSummary.Downtime_DurationInMinutes_Category0}, {WorkCntrSummary.Criteria_MachineID},{WorkCntrSummary.Criteria_StartDateTime});
numberVar xh := Truncate(Round(x)/60);
numberVar xm := Round(x) mod 60;
if xh >= 1 then
ToText (xh, 0) + "h " + ToText (xm, 0) + "m"
else
ToText (xm, 0) + "m"
But I get an error group condition must be a string.
Any help would be much appreciated.
Thanks!

Change
Sum ({WorkCntrSummary.Downtime_DurationInMinutes_Category0}, {WorkCntrSummary.Criteria_MachineID},{WorkCntrSummary.Criteria_StartDateTime})
to
Sum ({WorkCntrSummary.Downtime_DurationInMinutes_Category0}, {WorkCntrSummary.Criteria_StartDateTime})
In Crystal, the 2nd argument is what you group on. No need to chain all the grouping elements.

Related

Convert Amount to Words in Crystal Report

I am working on a crystal report, can someone guide me how i can convert currency to words in this format;
(1,502,000.50) One million five hundred and two thousand naira and fifty kobo Only. i have tried:
numberVar x := {#summAmt} - int ({#summAmt});
if x = 0 then
propercase (toWords (int({#summAmt}),0)+ ' Naira Only')
else
propercase (toWords (int({#summAmt}),0)+ ' Naira, and ' + toWords ((x * 100),0) + ' Kobo')
To go around this, you will need 2 formulas; create the one i posted earlier, then create then create another formula with the following code:
numberVar x := {#summAmt} - int ({#summAmt});
if x > 0 then
replace ({#convertWords},"Hundred ","Hundred and " )
else
{#convertWords}
{#convertWords} is the name of my first formula and #summAmt is the name of the field i am converting.

crystal report: print missing records

i want to print missing records in crystal report .
i am using below formula in the report and i have placed this formula in details b section.
details a has normal report fields.
formula:
local numbervar firstemp; // first Emp#
local numbervar nextemp; // next Emp#
local numbervar diff; // difference between firstemp and nextemp
local numbervar increase; // increment for missing Emp#'s
local numbervar result;
increase := 0;
firstemp := tonumber({getRptSalesSummery;1.Bill_Id});
nextemp := tonumber(next({getRptSalesSummery;1.Bill_Id}));
nextemp := nextemp -1;
diff := nextemp - firstemp;
if nextemp = firstemp
then ""
else (
while diff >= 1
do (
diff := diff - 1;
increase := increase + 1;
result := firstemp + increase;
exit while;
);
totext (result,"0000") & chr(13);
)
this formula is not giving me range.
for example if in report there is range of 1 to 10 and 6,7,8,9 is missing records, then if i check in the report its printing 1 to 5 and 6 as missing then directly 10, but its not giving me 7,8,9.
basically i required range of missing records

Converting numbers to MM:SS format in Cross-tab

I'm trying to convert a value in Cross-tab of Crystal report into a MM:SS format. I used the following steps: Right-click summary > Format Field > Display String > x+2
WhilePrintingRecords;
NumberVar curr := CurrentFieldValue;
NumberVar mins := Truncate(curr / 60);
NumberVar secs := Remainder(curr, 60);
ToText(mins, 0, "") & ":" & ToText(secs, 0, "")
The results are ok when the secs is not 0. Example: `4:30'
But, I am having problems when secs is 0, the result is (for 4 minutes): 4:0
I would like to have the output as 4:00, with the seconds display as always a 2 digit number.
Thank you for all your help
You my ElapsedTime function in conditional-formatting expression.
I used this instead, and it worked :)
NumberVar curr := CurrentFieldValue;
NumberVar mins := Truncate(curr / 60);
NumberVar secs := Remainder(curr, 60);
ToText(mins, 0, "") & ":" & ToText(secs, '00')

Crystal Reports Formula to generate a random number

Let assume
x = 1001
Now I am inputting x to my code and generating y in the following order:
Length of 1001 is 4 so starting from the last number
i.e. 1(number) * 4(position of number) & 0 * 3 & 0 * 2 & 1 * 1 that gives a new number 4001
Another eg. 1234 gives 16941
In crystal I am creating a formual as follows:
stringvar tmp_EventNo;
stringvar tmp_Password;
numbervar i;
numbervar m_password;
tmp_EventNo = Trim(ToText({GR_EVENT.event_number}));
For i := Len(tmp_EventNo) To 1 Step -1 Do
(
tmp_PassWord = tmp_PassWord & Trim(ToText(Val(Mid(tmp_EventNo, i, 1)) + i));
);
m_Password = Val(tmp_PassWord);
m_password
But it doesnt seem to work. Just results in 0.00
Please help thanks in advance
Nice easy one- you will kick yourself :)
In Crystal = is used for evaluation. := is used for assignment.]
There were a few other issues with the code so i tweaked it for you:
stringvar tmp_EventNo;
stringvar tmp_Password;
numbervar i;
numbervar m_password;
tmp_EventNo := Trim(ToText({GR_EVENT.event_number}, 0, ''));
For i := Len(tmp_EventNo) To 1 Step -1 Do
(
tmp_PassWord := tmp_PassWord & Trim(ToText(Val(Mid(tmp_EventNo, i, 1)) * i,0));
);
m_Password := Val(tmp_PassWord);
tmp_PassWord;

crystal reports : character "." in domain string errors

My goal is the discern whether the domain has a subdomain or not by counting the number of periods there are in the domain name. If it has 2 periods, there is obviously a subdomain.
I have the following crystal reports formula written in crystal syntax
local numbervar count :=0;
Local numbervar strLen := length({?domain});
local stringvar c := {?domain};
local numbervar i;
local numbervar pos2 :=0;
for i:=1 to strLen do
( if Mid({?domain}, i, 1) = "." then
(
count := count + 1;
if count = 2 then (
pos2 := i
);
);
);
if count > 1 then
left({?domain}, pos2)
else
left({?domain},instr({?domain}, ".")-1)
any ideas? hopefully this is something my tired eyes are just glazing over.
UPDATE: here is the weird thing that happens.
If I add "+ totext(pos2)
if count > 1 then
left({?domain}, pos2) + totext(pos2)
else
left({?domain},instr({?domain}, ".")-1)
it outputs correctly subdomain.domain with the .com removed
if i run it without the totext(pos2)
if count > 1 then
left({?domain}, pos2)
else
left({?domain},instr({?domain}, ".")-1)
it only shows the subdomain part of subdomain.domain.com
Any ideas why?
Should there be a final ; on the last line?
Alternatively, have you considered making the entire formula something like:
Left({?domain},InStrRev({?domain}, ".")-1)