If you are reading this blog post while travelling, there is good news for you. You can finish reading this blog before you reach your destination. It would save you 10 minutes of your time googling for a solution. In this blog, I would provide a solution to a use case where you need to process multiple files and you need to append the same timestamp column. In case you want all the rows to have the same processing time, the solution below will help you.
What does it do?
If there is a file with records, the Alteryx flow will add a new column with the same timestamp. This is useful when you want all the records to have the same timestamp when the workflow completes. This is done using a generate rows tool. An alternate approach using just the formula tool will not give the result as the rows will have a different timestamp (based on execution of the formula tool).
How to generate the timestamp?
This is a particular use case to use generate rows tool. This is a tool as its name says, to generate new rows. Typically it can be used to fill gaps in your data. It has 3 parts
Initialization expression: This is the initial value that is set when the generate tool is run the first time. After that for every other execution condition expression is checked. e.g counter =0
Condition Expression: This is the condition if it is true then Loop Expression is executed which usually is an increment. e.g counter < 100
Loop Expression(Usually Increment): Usually the variable used is incremented e.g counter = counter +1
For this particular case, generate rows tool is used is to create a timestamp in the initial value section. Then increment it and make it fail for all other executions. So with this approach, even when generate rows tool is called repeatedly, the timestamp has the same value and is not changed.
This will be clearr in the example workflow below:
Step by Step process
Step 1: Get the input file into the Alteryx workflow as below.
Step 2: Connect the input file to the Append tool. It has 2 anchors i.e. ‘Target T’ anchor and the Source ‘S’ anchor. The append tool will add each field provided to ‘S’ anchor to alls row in data provided to T anchor.
Step 3: Drag the generate rows tools to the Append tool.
Configure the tool as below. Create a new DateTime field. Initialize the expression using DateTimeNow(). This will get the current timestamp.
Step 4: Connect the generate rows to the append tool and configure the append tool as below. The append tool every row in S anchor and it is appended to all the rows in T anchor. Here the target is a set of 6 rows from the input tool. The source is just 1 row from the date processed from generate rows tool
Step 5: Once you run the workflow you get the results as below. You are good to go!
Hope this blog post helped you learn a new facet about generate rows tool and the use of the append tool.