# QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Become an analytics expert with Qlik's new 15 week course: Applied Data Analytics using Qlik Sense. READ MORE
cancel
Showing results for
Did you mean:
Contributor

## Duration between times over two rows

Hi

What I'm trying to do is find the duration between start and finish times for each employee for each date.

Im thinking something along the lines of :

If event type = F THEN use the previous row to get TimeIn and then work out the difference between the two time.

Bear in mind dates would have to be sorted correctly so it starts at the right point and the system would need to account for when it moves onto a row with a new employee.

Many thanks

1 Solution

Accepted Solutions
MVP

Hi,

maybe one solution could be:

```table1:
Timestamp(Floor(Date)+Alt(TimeIn,TimeOut)) as DateTime,
If(IsNum(TimeIn),'In','Out') as InOut

table2:
FullName,
Previous(DateTime) as DateTimeIn,
DateTime as DateTimeOut,
Interval(DateTime-Previous(DateTime)) as Duration
Resident table1
Where InOut='Out' and Previous(InOut)='In' and Code=Previous(Code)
Order By Code, DateTime;

DROP Table table1;
```

hope this helps

regards

Marco

4 Replies
Master II

See attached qvw:

MVP

Hi,

maybe one solution could be:

```table1:
Timestamp(Floor(Date)+Alt(TimeIn,TimeOut)) as DateTime,
If(IsNum(TimeIn),'In','Out') as InOut

table2:
FullName,
Previous(DateTime) as DateTimeIn,
DateTime as DateTimeOut,
Interval(DateTime-Previous(DateTime)) as Duration
Resident table1
Where InOut='Out' and Previous(InOut)='In' and Code=Previous(Code)
Order By Code, DateTime;

DROP Table table1;
```

hope this helps

regards

Marco

Contributor
Author

Thank you Marco - this works perfect.

Contributor
Author

Thank you mw  - this also works perfect.