Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
smiling_cheetah
Creator
Creator

Changing session number depending on time difference

Hi everyone, I came across this task:

change the number of session in case user was inactive for more that 30 minutes.

Would appreciate any help

So I have the following input data on logs:

TimeSessionetc...
10:00:001
10:05:001
10:50:001
11:00:001
11:55:001

I want to check the difference between two consecutive timestamps and if the difference is greater that 30 min, I assume that user has ended previous session and started a new one, like:

TimeSessionetc...
10:00:001
10:05:001
10:50:001.1
11:00:001.1
11:55:001.2

I assume my code would look something like, but it obviously wouldn't work

Table:

load Time,

  //Session,

  if(Previous(Time) - Time > 30, Session+0.1, Session) as Session

Resident Table_tmp;

Would appreciate any help, thank you

1 Solution

Accepted Solutions
sunny_talwar

Try this:

Table:

LOAD Time,

    Session

FROM

[https://community.qlik.com/thread/237857]

(html, codepage is 1252, embedded labels, table is @1);

FinalTable:

LOAD *,

  If(Time - Previous(Time) > MakeTime(0, 30), Peek('New_Session')+0.1, Alt(Peek('New_Session'), Session)) as New_Session

Resident Table

Order By Time;

DROP Table Table;

Capture.PNG

View solution in original post

2 Replies
sunny_talwar

Try this:

Table:

LOAD Time,

    Session

FROM

[https://community.qlik.com/thread/237857]

(html, codepage is 1252, embedded labels, table is @1);

FinalTable:

LOAD *,

  If(Time - Previous(Time) > MakeTime(0, 30), Peek('New_Session')+0.1, Alt(Peek('New_Session'), Session)) as New_Session

Resident Table

Order By Time;

DROP Table Table;

Capture.PNG

smiling_cheetah
Creator
Creator
Author

That's actually amazing,

works just as needed

Thank you Sunny