Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Sort Fields while Preserving Data Types

CGS123
5 - Atom

Is there a way to sort fields based on name while preserving the fields' data type?

 

I'm creating a macro at the end of which certain fields are sorted into a specific order--note, the fields fed into the macro are dynamic.  The macro is set up such that fields are renamed with a number prefix for ordering and then sorted according to their name.  After sorting, the prefix is removed.

 

I have not been able to sort based on field names with the select tool unless I'm in the macro and sort them manually--i.e., go to the select tool, chose options > sort > sort on field name > ascending.  I've tried using a check-box to update the 'order changed' property within the select tool, but it doesn't seem this does anything.

 

Using the Crew macro 'Field Sort' is not an option, at least not without some modification, as running data through this converts all fields' data type to string.

 

Thanks in advance!

4 REPLIES 4
CharlieS
17 - Castor
17 - Castor

The first thing that comes to mind is build a second macro to act as a shell for the original macro. This macro would determine the field types and order or the fields and update the XML of the select tool of your macro.

 

If I have some time (and someone else doesn't beat me to it), I'll build an example.

 

 

tlarsen7572
11 - Bolide
11 - Bolide

Some of us in the community have created a small group of custom, unofficial, Python tools.  One of these tools is a field sorter which can do what you want.  One of the options in the tool is to sort fields alphabetically.  The tool, by design, always retains the original data types:

SNAG-0030.png

 

If a custom tool is an option for you, you can download it from here.  Installation should be easy: just double-click on the installer and it will get installed into the Preparation tab.  Everything is open source; you can view the code and the other tools from our main Github page.

joona_rauhamaki
8 - Asteroid

Hi,

 

I love the Python sort macro. However, I am having some trouble with it:

 

1) where is this macro installed? Everything works just fine with it, but I would like to run the macro on our server, and to be able to do it, I would like to have the macro in a shared drive and refer to that location.

tlarsen7572
11 - Bolide
11 - Bolide

Hey @joona_rauhamaki, if you install it as a non-admin, the default installation directory should be something like:

 

C:\Users\YourUserId\AppData\Roaming\Alteryx\Tools

 

If you install it as an admin for all users the custom tool should go to:

 

C:\ProgramData\Alteryx\Tools

 

So if you want to install it on the server for all users, this is where I would usually put it.  Because it is not a macro, I am not sure you can install it to a custom shared location (like the macro library from the user settings dialog).

Labels