We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Column rearrangement based on a formatting file.

The1804
7 - Meteor

Hi everyone,

I am trying to get column structure and order in one file (Input1) based on a different file (Input2).

 

Input1

USER1USER6USER2USER4USER9
535MKO111RRR765
REEWNJ8222FFFUYT
YRFBHU333DFDYTR
45T765444FDFTRE

 

Input2

FIELDS
USER0
USER1
USER2
USERG
USER4
USER5
USER9
USER7
USER8
USER6

 

My current solution is very close to achieving that task. However it doesn't respect empty columns and pushes everything to the left.

 

USER1USER6USER2USER4USER9USER0USERGUSER5USER7USER8
535MKO111RRR765     
REEWNJ8222FFFUYT     
YRFBHU333DFDYTR     
45T765444FDFTRE     

 

My expected result looks like this.

USER0USER1USER2USERGUSER4USER5USER9USER7USER8USER6
 535111 RRR 765  MKO
 REEW222 FFF UYT  NJ8
 YRF333 DFD YTR  BHU
 45T444 FDF TRE  765

 

If someone could take a look at my flow and give me a hint I would really appreciate it. Ideally I would like to convert the solution into a macro so it can be reused with many different column patterns.

My real data has over 50 columns.

11 REPLIES 11
caltang
17 - Castor
17 - Castor

It will have to follow certain naming conventions and your data will be transformed. But instead of making it a macro, you can reuse @DataNath or my workflow within a workflow - that doesn't take up too much time nor processing power.

 

If you do insist on a macro, then yes - it is better to open a new thread.

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
DataNath
17 - Castor
17 - Castor

No need to open up a new thread - turning my flow into a macro requires 2 incredibly simple changes: make the Text Input tools Macro Input tools and then add a Macro Output tool after the union:

 

5001.png

 

Now if I place this in a new workflow with my field order:

 

5002.png

 

And some starting data (again, out of order and with not all fields present):

 

5005.png

 

Output is as desired:

 

5003.png

 

One thing to note: If you'll always be using [FIELDS] as the name for the mapping/order list, you can leave things as they are. However, if this column name can be something different like [FieldNames], [FieldOrder] etc, then you'll need to enable Field Mapping in this Macro Input anchor. You can do that here:

 

5004.png

 

This just allows you to map [FIELDS] - that has been used to build the macro - to the equivalent in the actual dataset you're using so that instances of it can be replaced when it runs.

 

Macro and example workflow both attached as a packaged workflow. Hope this helps!

Labels
Top Solution Authors