Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Summary & average - need help Post Reply Post New Topic
Author Message
daniel123
Newbie
Newbie


Joined: 11 Feb 2014
Location: Zambia
Online Status: Offline
Posts: 2
Quote daniel123 Replybullet Topic: Summary & average - need help
     Posted: 12 Feb 2014 at 8:19pm
guys need your help here... pls Wink
I am trying to monitor the timings of the employees everytime they used their ID. So in 1 day they might swipe the ID many times.
 
what i did is get the time difference (date,hour & minutes) for 2 dates.
 
date format: 02-Feb-2014 10:31 
 
1st formula is:
local numbervar tt := datediff('n',{IDswipe startdate},{IDswipe enddate});
local numbervar d := truncate(tt/1440,0);
local numbervar h := truncate(remainder(tt,1440)/60,0);
local numbervar m := truncate(remainder(tt,60),0);
local stringvar tt_d := if d=0 then "" else totext(d,0,"") + 'd ';
local stringvar tt_h := if h = 0 then "" else (totext(h,0,"")) + 'h ';
local stringvar tt_m := totext(m,0,"") + 'm ';
local stringvar tt_string := tt_d & tt_h & tt_m
 
Result of the formula : ex. 2d 17h 22m
 
2nd formula : {IDswipe enddate} - {IDswipe startdate} 
 
Result = 1.5 (meaning 1 day and 12 hrs.)
 
Both formulas are successful
 
here is the tricky part: I want to get the summary of all time differences and Average per Employee. How can i do this? Using the Insert Summary/Averrage does not get the correct numbers. I am having difficulty in creating formula to get the Summary and Average per Employee.
 
FYI - all the details are in GROUP HEADER  
 
will really appreciate your help ClapSmile
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 13 Feb 2014 at 4:57am
use variables.
Group header reset:
shared numbervar cnt:=0;
shared numbervar tot:=0;
"" //hide the 0 that would be displayed

increment, in the formula
shared numbervar cnt;
shared numbevar tot;

cnt := cnt +1;
tot := tot + Result; //maybe, it would be up to you
""//again hide the total

display, group footer:
shared numbervar cnt;
shared numberver tot;
if cnt > 0 then
tot/cnt;
else
0;

this is a rough outline.
HTH
IP IP Logged
daniel123
Newbie
Newbie


Joined: 11 Feb 2014
Location: Zambia
Online Status: Offline
Posts: 2
Quote daniel123 Replybullet Posted: 15 Feb 2014 at 5:54pm

i really appriciate your reply

but is there any way you can make this simple :)
 
as i am not a really getting what you mentioned.. Sorry but still newbie in CR
 
thanks  again
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 17 Feb 2014 at 7:08am
here's the problem...you want to summarize something selectively. CR doesn't work that way, when it wants to summarize something using a function like SUM or AVG, it does it while it is reading the data (CR makes multiple passes through the data).

Your formula 'runs' while CR is printing the records (too late for the summary functions) so CR can't use SUM or AVG or any of the aggregated functions, so you have to do it yourself. In order for you achieve this, you need to use global or shared variables (they are basically the same).

The rough outline given, is how to a variable to create a variable and how to populate it. The big mystery to me, is how to increment it, as that is logic that you should know.

Hope this is a bit clearer
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum