Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
JJaky
Contributor III
Contributor III

Calculate difference in time for different rows

Hi all, can anyone help me to solve my issue:

i need to calculate time difference in days for one id but different events. My table looks like this:

JJaky_0-1614267645129.png

I need to calculate time difference only for events 1 and 2. 

Thanks in advance for hints!

Labels (1)
5 Replies
duchezbr
Contributor III
Contributor III

Create an additional field in your load script. Try with the script below to see if the output is what you are looking for.

Set dateformat = 'DD/MM/YY';

Table:
Load * inline [
product, event, dates
product a,1,11/02/21
product a,2,15/02/21
product b,1,10/02/21
product b,2,10/02/21
product b,3,12/02/21
];


Load
product,
event,
dates,
If(event = 2, Interval(dates - Previous(dates), 'D')) as date_diff
Resident Table
;

drop Table Table;

Saravanan_Desingh

Can you show the expected output with the sample above?

PrashantSangle

provide some more data, also provide desired output.

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
JJaky
Contributor III
Contributor III
Author

Hi all, here's some more data with expected result table

JJaky_0-1614325865284.png

I guess I need to calculate another table, but would be grateful for other ideas) 

duchezbr
Contributor III
Contributor III

You can use a pivot table (see attachment for desired output).  The value fields were created in the load script using the provided data and the if statement below:

If(event='event 2', Interval(dates - Previous(dates), 'D')) as [Event 2-1]
If(event='event 3', Interval(dates - Previous(dates), 'D')) as [Event 3-2]