Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
wanyunyang
Creator III
Creator III

Multiple time lapses

I'm not able to show company data so I made up a similar scenario: I'm trying to calculate the time lapse between Question Status and Answer Status. And the problem is, what should the expression be if there are multiple Question-Answer pairs, which leads to multiple time lapses?

For example, in below scenario, there should be two time lapses: 00:03 (from Id 336 and 339) and 00:04 (from Id 346 and 347).

w.PNG

Thank you in advance!

1 Solution

Accepted Solutions
dwforest
Specialist II
Specialist II

You could use something like

If (Previous(Status)='Question' and Status='Answer', time-Previous(time), 0)

View solution in original post

7 Replies
Quy_Nguyen
Specialist
Specialist

How do you know which answer belongs to which question?

wanyunyang
Creator III
Creator III
Author

Based on Id is fine. Just get the closest Answer to each Question. .

Quy_Nguyen
Specialist
Specialist

OK. Assumed that every question has the answer, the idea is create a Question-Answer table from your data to achieve your request. Here is the sample code for you:

Temp:

LOAD

    RowNo() As PairID,

    ID as ID_Question,

    "Time" As TimeStart

FROM [YourConnection]

Where Status = 'Question';

Join

LOAD

    RowNo() As PairID,

    ID as ID_Answer,

    "Time" As TimeEnd

FROM [YourConnection]

Where Status ='Answer';


FinalData:

Load *, Time(TimeEnd-TimeStart,'hh:mm') As TimeLapse

Resident Temp;


Drop Table Temp;


wanyunyang
Creator III
Creator III
Author

Hi Quy, thanks for your reply, but unfortunately, not every Question has Answer. What I'm thinking of is if there's a way to use above() function in chart.

dwforest
Specialist II
Specialist II

You could use something like

If (Previous(Status)='Question' and Status='Answer', time-Previous(time), 0)

wanyunyang
Creator III
Creator III
Author

Hi David, it says Previous is not a valid function.

wanyunyang
Creator III
Creator III
Author

Oh I see. It's a script function. Thanks David!