Jun 23, 2015

How to re-order columns in EasyMorph

By default, EasyMorph adds new columns after the rightmost column of a table. Although, sometimes there is a need to change the order of columns. As of version 1.8 EasyMorph doesn't have a dedicated transformation for re-ordering columns (we're still thinking if we should make such transformation or re-order columns in a different way). However, it can be achieved using a simple technique:

We can use the fact that Append Table transformation keeps the order of column of the primary table. This transformation matches column names in the primary table and the external table (the one which is appended). Columns of the external table with matching names are appended at the bottom of the primary table's columns. Non-matched columns are added after last column of the primary table (if this sounds complicated to you -- take a look at examples in web-help for Append Table).

Therefore, we can order to re-order columns in 2 simple steps:

Step 1. Create an empty table with columns in the right order.
Step 2. Append our table to that empty table.

Creating an empty table for Step 1 is simple:
1. Use Sequence transformation to generate a table with 1 row.
2. Use Calculate new columns transformation to create new columns in the right order.
3. Remove the only row using Filter.
4. Remove column [Count] using Remove Columns.




And then append the table with data to the empty table:


As you can see, the columns are now in the right order.