Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
drohm002
Creator II
Creator II

help calculating differnce in days, based off multiple factors

Please see the table below.  I would like to calculate the duration of each ID, the difference between the last date and the first date, in relation to event X.  So for ID 1, the answer I am looking for is four days, but I do not know the logic and calculation to get there....please help!

   

IDeventtime
1x6/5/2018
1x6/6/2018
1x6/7/2018
1x6/8/2018
2x6/9/2018
2x6/10/2018
2x6/11/2018
3x6/12/2018
3x6/13/2018
3x6/14/2018
9 Replies
vishsaggi
Champion III
Champion III

Did you try like LastDate - FirstDate?

IN your sample data there is no lastdate and first date fields.

settu_periasamy
Master III
Master III

May be try this.

=Max(TOTAL  <ID>time)-Min(TOTAL  <ID>time)+1

vishsaggi
Champion III
Champion III

Hush! I got it now. Hes is looking for Min and Max times by ID.

sergio0592
Specialist III
Specialist III

Hi, and if you just use max and min in a chart?

Is it what you're trying to achieve?

Anonymous
Not applicable

Daniel,

try the below snippet

Temp_cumulative:
LOAD ID,event, Date(Date#(time,'MM/DD/YYYY')) AS time;
LOAD * Inline [
ID event time
1 x 6/5/2018
1 x 6/6/2018
1 x 6/7/2018
1 x 6/8/2018
2 x 6/9/2018
2 x 6/10/2018
2 x 6/11/2018
3 x 6/12/2018
3 x 6/13/2018
3 x 6/14/2018
]

(
delimiter is ' ');

SET VEvaluate= ($1-$2)+1;

Left Join (Temp_cumulative)
LOAD *,
$(VEvaluate(num(Maxtime),num(Mintime))) AS duration;
LOAD
ID, event,
Date(max(time)) AS Maxtime,
Date(min(time)) AS Mintime
Resident Temp_cumulative Group by ID,event;

drohm002
Creator II
Creator II
Author

that is because there is only one column in my data that has the date.  I am looking for the duration of event 'X', for each ID.  So the duration for ID 1 is 4 days...

drohm002
Creator II
Creator II
Author

I need to find the duration of event 'X' for each ID.  So the correct answer for ID 1 is a duration of 4 days for event X....

drohm002
Creator II
Creator II
Author

all my dates are in the same column, I do not have two separate columns of min and max

olivierrobin
Specialist III
Specialist III

hello

load your data

and in your graph, use :

ID as dimension

and

=FirstSortedValue(time,-time)-FirstSortedValue(time,time)+1

as expression