Join the Alteryx Community’s Maveryx Summer Cup event! Compete, network with others, and earn your gold through a series of challenges from July 24th to August 11th. Learn more about the event here.

Alteryx Designer Desktop Discussions

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

Macro to join multiple files in directory

bhauteshved
7 - Meteor

I would like to create a macro to join multiple text files. Each file will have common column headers separated by tabs. The number of files can vary. Any help? 

2 REPLIES 2
Thableaus
17 - Castor
17 - Castor

Hi @bhauteshved 

 

Is it a union or a join? Because it looks like you want to union this data (put rows below rows).

 

Cheers,

estherb47
15 - Aurora
15 - Aurora

Hi @bhauteshved 

 

If you want to union them together (that is, combine all files into one longer file), you can do this without a macro, by using a wildcard input. Configure your input tool to look like this: 


image.png

This will string file 2 input after file 1, etc., until all of the files are combined.

If you want to read in all of the files and have each new text file drive into a new column, joining the fields by position, be sure to choose "File Name Only" on option 4 of the input tool, Output File Name as Field.
image.png

Then add a crosstab tool, with a grouping level of "Position", Column Header of "File Name" and Values of "Number". I used "Concatenate" because the numbers are stored as text. If you convert them to a number, you can use Sum
image.png

Finally, here is the result:
image.png

 

I suppose you could turn this into a macro if you wanted to. With 2 tools, I tend to just use them instead of a macro :)

Cheers!

Esther

Labels