Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Retrieve records >=24 hours for given Location and Customer id

Dhanushka_A
7 - Meteor

Hi All,

 

I want to retrieve records which are >=24 hours for given location and customer id. How do I achieve this without having many Multi-row tools?

 

Original Data set

LOCATION_IDCUSTOMER_IDDATESEQUENCE_NO
20010020414707902018-08-24 02:10:001
20010020414707902018-08-25 21:01:002
20010020414707902018-08-30 11:20:003
20010020414707902018-09-01 02:16:004
20010020414707902018-09-02 16:32:005
20010020414707902018-09-05 23:45:006
20010020414707902018-09-06 11:51:007
20010020414707902018-09-07 02:06:008
20010020414707902018-09-07 16:15:009
20010020414707902018-09-08 04:33:0010
20010020414707902018-09-08 16:56:0011
20010020414707902018-09-09 07:24:0012
20010020414707902018-09-10 09:00:0013
20010020414707902018-09-13 10:02:0014
20010020414707902018-09-14 02:24:0015
20010020415869602018-08-16 22:15:001
20010020415869602018-08-17 11:48:002
20010020415869602018-08-18 02:56:003
20010020415869602018-08-23 11:40:004

 

 

Need to get

 

LOCATION_IDCUSTOMER_IDDATESEQUENCE_NO
20010020414707902018-08-24 02:10:001
20010020414707902018-08-25 21:01:002
20010020414707902018-08-30 11:20:003
20010020414707902018-09-01 02:16:004
20010020414707902018-09-02 16:32:005
20010020414707902018-09-05 23:45:006
20010020414707902018-09-07 02:06:008
20010020414707902018-09-08 04:33:0010
20010020414707902018-09-09 07:24:0012
20010020414707902018-09-10 09:00:0013
20010020414707902018-09-13 10:02:0014
20010020415869602018-08-16 22:15:001
20010020415869602018-08-18 02:56:003
20010020415869602018-08-23 11:40:004

 

Thanks,

Dhanushka

2 REPLIES 2
danilang
19 - Altair
19 - Altair

Hi @Dhanushka_A 

 

you can do it in a single Multi-Row tool if you use the following formula, grouped by Location_id and customer_id

 

if isnull([row-1:timediff]) then
	0
elseif [Row-1:TimeDiff]+datetimediff([DATE],[Row-1:DATE],"seconds")>=24*60*60 then
	0
else
	[Row-1:TimeDiff]+ datetimediff([DATE],[Row-1:DATE],"seconds")
endif

 

 

The first if handles the first record in every group.  The next one checks if the previous time difference + the current time difference >= 24 hours and sets the time difference for the current row to 0.  The else clause adds the previous difference to the current and stores that.  If effectively creates a running total that resets to 0 if it goes above 24 hours.  Then you discard all the records that have a non-zero difference

 

Dan

 

  

Dhanushka_A
7 - Meteor

Thanks Dan. I'm embarrassed to admit that I did not realize that we can use the new field "TimeDiff" within the expression until now. 

 

Cheers,

Dhanushka

Labels