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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
coco832
Contributor II
Contributor II

Dates between rows - Matching ID & Time - Interval/Peek/Min [Script][Sense]

Hi,

I am trying to get the state duration for the next table:Captura0.PNGI try to create a script where i can peek the minimum date where the resource ID match and the date is older than the one from the row, then I get the timestamp between the two dates. But I am getting an error. There my sample & Error (sorry about SPA):

SQL (guideline): select Min(eventdatetime) from agentstatedetail where agentstatedetail.resourceID equal resourceID And agentstatedetail.eventdatetime >= eventdatetime;

CapturaA.PNG

 

CapturaB.PNG

Anyone knows what I am missing? Error code is as useful as windows problem solver. I am not able to modify the data source.

Labels (1)
1 Solution

Accepted Solutions
coco832
Contributor II
Contributor II
Author

After few day i was not able to find a direct solution using Qlik Script functions, there you got  a solution with SQL:

This is an inaccurate solution.

SQL SELECT mt.agentid,
	mt.eventdatetime,
	mt2.eventdatetime AS nexteventdatetime,
	mt2.eventdatetime - mt.eventdatetime AS stateduration
  FROM (
SELECT
	sd.agentid,
	sd.eventdatetime,
	ROW_NUMBER() OVER( ORDER BY sd.agentid ASC, sd.eventdatetime ASC) AS this_row_nr,
	( ROW_NUMBER() OVER( ORDER BY sd.agentid ASC, sd.eventdatetime ASC) ) + 1 AS next_row_nr
  FROM 
	informix.agentstatedetail	AS sd
) AS mt
  LEFT JOIN
(
SELECT
	sd.agentid,
	sd.eventdatetime,
	ROW_NUMBER() OVER( ORDER BY sd.agentid ASC, sd.eventdatetime ASC) AS this_row_nr,
	( ROW_NUMBER() OVER( ORDER BY sd.agentid ASC, sd.eventdatetime ASC) ) + 1 AS next_row_nr
  FROM 
	informix.agentstatedetail	AS sd
) AS mt2
    ON mt.agentid = mt2.agentid 
   AND mt.next_row_nr = mt2.this_row_nr;

View solution in original post

3 Replies
dwforest
Specialist II
Specialist II

Need a Group By for the Min()
coco832
Contributor II
Contributor II
Author

[agentstatedetailB]:
LOAD
	[resourceid],
	[agentstatedetail.eventdatetime],
	Interval(if(Peek([resourceid])=[resourceid] And Peek([agentstatedetail.eventdatetime])>[agentstatedetail.eventdatetime],Min([agentstatedetail.eventdatetime]))-[agentstatedetail.eventdatetime]) AS [Duration] 
    Resident agentstatedetail Group By [agentstatedetail.eventdatetime]
    ;

Still getting the error.errorqlik.PNG

 

coco832
Contributor II
Contributor II
Author

After few day i was not able to find a direct solution using Qlik Script functions, there you got  a solution with SQL:

This is an inaccurate solution.

SQL SELECT mt.agentid,
	mt.eventdatetime,
	mt2.eventdatetime AS nexteventdatetime,
	mt2.eventdatetime - mt.eventdatetime AS stateduration
  FROM (
SELECT
	sd.agentid,
	sd.eventdatetime,
	ROW_NUMBER() OVER( ORDER BY sd.agentid ASC, sd.eventdatetime ASC) AS this_row_nr,
	( ROW_NUMBER() OVER( ORDER BY sd.agentid ASC, sd.eventdatetime ASC) ) + 1 AS next_row_nr
  FROM 
	informix.agentstatedetail	AS sd
) AS mt
  LEFT JOIN
(
SELECT
	sd.agentid,
	sd.eventdatetime,
	ROW_NUMBER() OVER( ORDER BY sd.agentid ASC, sd.eventdatetime ASC) AS this_row_nr,
	( ROW_NUMBER() OVER( ORDER BY sd.agentid ASC, sd.eventdatetime ASC) ) + 1 AS next_row_nr
  FROM 
	informix.agentstatedetail	AS sd
) AS mt2
    ON mt.agentid = mt2.agentid 
   AND mt.next_row_nr = mt2.this_row_nr;