Print Page | Close Window

Calculation through multiple rows

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2022
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=163
Printed Date: 02 May 2025 at 12:32am


Topic: Calculation through multiple rows
Posted By: Henry
Subject: Calculation through multiple rows
Date Posted: 26 Jan 2007 at 5:06am
Hi
I would like to calculate the duration between to certain actions in our DB. The times reside in the same table in the columns but in different rows. Example:
"ID"     "Name"     "Task"        "Time"
"1"     "John"     "action begin"     "2007-01-25 10:00"
"2"     "John"     "action end"     "2007-01-25 10:10"
"3"     "John"     "action begin"     "2007-01-26 11:30"
"4"     "John"     "action end"     "2007-01-26 11:45"

I would like to report on the total duration from begin to end. Using the example above I want to indicate that John spent 25 minutes on his tasks.

WHERE DO I START WITH THIS? Any suggestions welcome...



Replies:
Posted By: BrianBischof
Date Posted: 26 Jan 2007 at 9:04am
Have two global variables. The first one accumulates the total time taken so far. The second one calculating the difference between the current action. Then do something like this.... (This is psuedo-code, so you will have to tweak it to make it actually work).

Global NumberVar TotalTime
Global DateTime ActionTimeStart

if {Table.Field} = 'action begin' then
       //start the timer
        ActionTimeStart = {Table.DateField};
else
       /calculate total time elapsed and save it
       TotalTime = TotalTime + {Table.DateField} - ActionTimeStart;




-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>



Print Page | Close Window