Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count with conditions crystal report

Status
Not open for further replies.

AngelaAS

Technical User
Mar 21, 2013
4
GH
hello ALl, can someone help me with the formula i have below

if ({@businesHours}<8) then count({MOBILE_NMC_Trouble_Ticket.Trouble Ticket ID})

am expecting it to return a value, but it returns nothing

formula checks records to count tt ids with @businesHours <8
 
can you perform a manual summary using a slightly modified formula?

{@EvalWithVar}
numbervar bh;
IF ({@BusinessHours}<8) then bh := bh + 1 else bh := bh;
bh

you could also do the same/or very similar using no variables and then performing a Summary on the formula;
Something like this:
{@EvalforSum}
IF ({@BusinessHours}<8) then 1 else 0;

You could then use either the built in Summary tool, or create a formula like:
{@EvalManualSum}
SUM({@EvalForSum},{GROUPEDtable.field})

 
Thnx Fisheromascse but i get an error with SUM({@EvalForSum},{GROUPEDtable.field})

it tells me {@EvalForSum} cannot be summarised
 
Can you provide the code for {@businesHours} (and any formulas referred to within that formula), and a description of the basic report setup, eg groups etc.

Cheers
Pete
 
ok pmax9999, please the code below

//Determine how many Business Hours
//are within a date range
WhilePrintingRecords;
//example (Y,M,D,H,M,S): datetime(2000,04,17,8,0,0)
DatetimeVar FDay:= {MOBILE_NMC_Trouble_Ticket.+Date_1};
//example (Y,M,D,H,M,S):Datetime(2000,04,18,17,0,0)
DatetimeVar LDay:= {MOBILE_NMC_Trouble_Ticket.+Date_2}; TimeVar
//example for 7:30 AM: time(7,30,0)
BusinessStartTime:= time(8,0,0);
//example for 5:00 PM: time(17,0,0)
TimeVar BusinessEndTime:= time(17,0,0);
NumberVar BSTime;
NumberVar BETime;
Numbervar Days;
Numbervar Weekends;
Numbervar Finaldays;
DateVar StartDate;
DateVar EndDate;
NumberVar halfdays;
NumberVar fulldays;
NumberVar hours;
//If first day or last day is null or less than null assign
//hours to 0 and finish the formula
if FDay <=Date(0,0,0) or LDay <=Date(0,0,0) then
hours:= 0
//Else assign hours
else
(
//Assign Business Start Time and Business End Time
BSTime:= hour(BusinessStartTime) +
(minute(BusinessStartTime) / 60);
BETime:= hour(BusinessEndTime) + (minute(BusinessEndTime) /
60);
//Assign First Day and Last Day
//Determine whether FDay falls within
//start time and end time
if hour(FDay) in BSTime to BETime then
FDay:= FDay
else if hour(FDay) > BETime then
FDay:= datetime(date(FDay)+1, BusinessStartTime)
else if hour(FDay) < BSTime then
FDay:= datetime(date(FDay), BusinessStartTime);
//Determine whether LDay falls within start
//time and end time
if hour(LDay) in BSTime to BETime then
LDay:= LDay
else if hour(LDay) > BETime then
LDay:= datetime(date(LDay), BusinessEndTime)
else if hour(LDay) < BSTime then
LDay:= datetime(date(LDay)-1, BusinessEndTime);
//Assign StartDate and EndDate
//if the first day falls on a weekend,
//StartDate is equal to the following Monday
//for calculation reasons
If DayOfWeek(FDay) = 7 Then
StartDate := date(FDay) + 2
Else
If DayOfWeek(FDay) = 1 Then
StartDate := date(FDay) + 1
Else
StartDate:=date(FDay);
//if the last day falls on a weekend,
//EndDate is equal to the following Monday
//for calculation reasons
If DayOfWeek(LDay) = 7 Then
EndDate := date(LDay) + 2
Else If DayOfWeek(LDay) = 1 Then
EndDate := date(LDay) + 1
Else
EndDate := date(LDay);
//Calculate days (including First day and Last day)
Days:= (EndDate - StartDate)+1;
//Calculate Weekends
if Days >= 7 then
WeekEnds := (Round((Days/7),0))*2
else if DayOfWeek(StartDate) > DayOfWeek(EndDate) then
WeekEnds := 2
else
WeekEnds := 0;
//Calculate FinalDays
//If the Last Day is on a weekend then
//FinalDays subtract the weekend days
If DayOfWeek(LDay) = 7 then
FinalDays:= FinalDays - 1;
If DayOfWeek(LDay) = 1 then
FinalDays:= FinalDays - 2;
//Assign FinalDays to Days - Weekends
FinalDays:= Days - WeekEnds;
//Calculate Hours
//If there is less than 2 days, hours = last
//days hour - first days hour
If FinalDays <= 1 then
(if hour(LDay) <= BETime then
hours:= (time(LDay) - time(FDay))/3600
else
hours:= (BusinessEndTime - time(FDay))/3600)
//Else hours = how many hours on the two half
//days + how many hours for the full days
Else
(
halfdays:= ((BusinessEndTime - time(FDay)) /3600 +
(time(LDay) - BusinessStartTime)
/3600);
fulldays:= (FinalDays-2) * 9.5;
hours:= halfdays + fulldays;
);
);
//Display Hours
//Display the number of hours between
//the business day ranges
hours;
 
OK, I think I understand what you are trying to achieve here, and fisheromacse's suggestions (and probably should have just read his suggestion more carefully in the first place).

Which of his approaches did you try? There were actually 3 distinct suggested approaches. What code were you using for the {@EvalForSum} formula when you got the error "{@EvalForSum} cannot be summarised"?

Cheers
Pete.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top