Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

Insert rows based on a condition

AlterCom
8 - Asteroid

Hello,

 

Need your help in solving an issue.

 

I'm trying to insert a number of rows in the data. The number of rows isn't fixed. For eg. for some transactions, 2 rows have to be inserted, for others, the number is 5 and so on. 

 

Following data will clear this out:

 

date_timetime_slot
2019-08-21 10:23:1220-30
2019-08-21 10:24:0120-30
2019-08-21 11:14:0710-20
2019-08-21 11:23:0920-30
2019-08-21 11:50:4550-60

 

 

Desired output: 

 

date_timetime_slot
2019-08-21 10:23:1220-30
2019-08-21 10:24:0120-30
2019-08-21 10:30:0030-40
2019-08-21 10:40:0040-50
2019-08-21 10:50:0050-60
2019-08-21 11:00:000-10
2019-08-21 11:14:0710-20
2019-08-21 11:23:0920-30
2019-08-21 11:30:0030-40
2019-08-21 11:40:0040-50
2019-08-21 11:50:4550-60

 

Please guide!

4 REPLIES 4
MichalM
Alteryx Alumni (Retired)

@AlterCom 

 

Could you please provide a bit of direction around the logic you apply to insert the rows? Is it the missing time slots as each day needs to have all of these populated?

AlterCom
8 - Asteroid

@MichalM Yes! These are the missing time slots. Have marked them in bold in the post as well.

So basically, if there is no entry in the 10 min slot interval, then a dummy value of "start time of slot" should be inserted in the data

MichalM
Alteryx Alumni (Retired)

Gotya!

 

In which case I'd do the following

 

  • Assign the existing date_time values to the appropriate rounded slots
    • I split the date time into date and time
    • And used a formula shared by @jdunkerley79 here
DateTimeAdd(
[date_time1],
Round(
  DateTimeDiff([date_time], [date_time1], "minutes")
   , 10)
, "minutes")

 

  • Calculate Min and Max of date time
  • Use the Generate Rows tool to calculate all 10min increments between Min and Max
  • Use the minute information from date_time to generate time_slot 
DateTimeFormat([date_time],"%M") + "-" + DateTimeFormat(DateTimeAdd([date_time], 10, "minutes"),"%M")

 

  • Finally, perform a right outer join by combining the Join tool and the Union tool to append the missing data

 

Example workflow attached

 

missing-slots.png 

AlterCom
8 - Asteroid

@MichalM Thank you!

Labels