This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
on 09-22-2016 04:30 PM - edited on 07-27-2021 11:36 PM by APIUserOpsDM
If you have a file that doesn't have the field names in the header row but rather in the first row of data, the Dynamic Rename Tool has an option to take field names from first row of data, which allows you to rename your headers easily and dynamically.
But what if you have many files in a directory, all with the same problem?
You want to combine these two files and turn them into one clean output:
But you don't want to have to map each and every one into Alteryx and use a Dynamic Rename Tool for each one of them....
The solution is to wrap a batch macro around the Input Tool and Dynamic Rename Tool. This will let you read in each file individually, fix their header row and then combine them into one dataset!
It's a fairly simple macro:
It accepts full file paths as the input, which are used to update the file mapped into the Input tool inside the macro. The Dynamic Rename Tool is set to accept "Dynamic or Unknown Fields" so it will pick up on any column from an input file. It then replaces the current header with the values found in the first row of data.
The macro "holds" the data until all iterations have run (all files have been read in) and then unions the data together based on field names because we selected "Auto Configure by Name" as the Output Mode:
To use the macro in a workflow, point a Directory Tool to the folder containing the files to be read in and then use the Full Path to feed into the macro.
See the attached workflow for an example.