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

EDIT: Sorry, my bad - just realized the order was out. Just let me check.

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

Hey @The1804, here's how I'd go about it:

 

1) Add a RecordID so we can Cross-Tab the [FIELDS] into the first row of data, in the desired order

2) Cross-Tab, setting the RecordID as the headers (as Alteryx orders them ascending by default)

3) Dynamic Rename to take the actual desired header i.e. the [FIELDS] value from the first row

3) Sample the first 0 rows so we're only left with the headers

4) Union this desired structure with the main data - ensure the configuration is as below to force the order etc

 

5000.png

 

Workflow attached - hope this helps!

caltang
17 - Castor
17 - Castor

Here is my way, fixed:

image.png

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
niklas_greilinger
10 - Fireball

One way of doing this is to change the configuration of the Union tool to Manually configure fileds. As @caltang mentioned this is a rather manual approach, but might help you too.

Rearrange_columns.pngRearrange_columns1.png

caltang
17 - Castor
17 - Castor

Although true, @The1804 has many more columns than what is shown. They will need a dynamic approach to suit their needs. Your Union changes are manually adjusted, which may not be dynamic enough for the requestor. Good for fixed use cases that you know won't change in fields.

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

Hi @niklas_greilinger please do not take my comment the wrong way. You should not edit your solution away, that is something that could help @The1804 down the road. If you can, please put back your solution so that it helps. 

 

Re: Your question on doing it with the Union tool itself, your method of manually adjusting IS the way to do it. Other than that, for it to follow a pre-determined order - you will need to measure it against something that is ordered already. In this case, the requestor has done so with the 2nd Text input tool.

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
The1804
7 - Meteor

Thank you everyone for the responses! @DataNath it seems like the only missing link in my solution was the order in which I attached my connectors to the last Union tool. That is actually very strange as "Set a specific output order" doesn't seem to be doing much. I actually had to disconnect the tools and connect my desired column order first and the data second.

Anyways, I will use this solution on my data now. Thanks again!

caltang
17 - Castor
17 - Castor

Small ask, @DataNath ’s one doesn’t seem to be following your desired order of columns right? 

My workflow sorts and follows the order you seek. If it helps, do you mind marking @niklas_greilinger and my workflow as accepted solutions as well since they serve your requirements @The1804 ?

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
The1804
7 - Meteor

Hi,

 

They both achieve exactly the same result. While the 1st solution is much simpler.

Of course I can also mark your solution as accepted as it also produces expected data.

 

Do you think it's possible to easily remake it into a macro so it can be used in multiple flows? I currently have around 65 flows which need this feature implemented and I don't really want to copy all the blocks to each of them. If no I will make a new thread regarding this question.

Labels
Top Solution Authors