Hi,
I have a query I am trying to build currently which creates a running total based on set criteria. I essentially have three columns (All times are in minutes). The visit ID, the duration of a visit and the time difference between the current and previous visit. e.g.
ID Duration Difference
1 30 0
2 45 10
3 15 20
4 60 10
5 15 10
What I would like to achieve is the following:
ID Duration Difference running total
1 30 0 30
2 45 10 85
3 15 20 15
4 60 10 85
5 15 10 110
So a line will have the calculation of the current time + the difference between the current and previous visit if the difference is below 20.
I have the following:
Which I put as Cont20([Duration],[Difference])
the problem seems to be on the return aspect, its not calculating correctly.
I had the formula in Excel which worked great, but this is proving troublesome. As a note the Excel formula was such that it would add the previous running total and then add the current duration and current diff. e.g.
In cell A7 the formula would be A6+B7+C7 and so on.
Any help would be awesome!
I have a query I am trying to build currently which creates a running total based on set criteria. I essentially have three columns (All times are in minutes). The visit ID, the duration of a visit and the time difference between the current and previous visit. e.g.
ID Duration Difference
1 30 0
2 45 10
3 15 20
4 60 10
5 15 10
What I would like to achieve is the following:
ID Duration Difference running total
1 30 0 30
2 45 10 85
3 15 20 15
4 60 10 85
5 15 10 110
So a line will have the calculation of the current time + the difference between the current and previous visit if the difference is below 20.
I have the following:
Code:
Public Function Cont20(MyVal As Long, MyDif As Long) As Long
Static OldValue As Long
Dim NewValue As Long
If MyDif >= 20 Then
NewValue = MyVal
OldValue = 0
Else
NewValue = MyVal + OldValue
OldValue = NewValue
End If
Cont20 = NewValue
End Function
the problem seems to be on the return aspect, its not calculating correctly.
I had the formula in Excel which worked great, but this is proving troublesome. As a note the Excel formula was such that it would add the previous running total and then add the current duration and current diff. e.g.
In cell A7 the formula would be A6+B7+C7 and so on.
Any help would be awesome!