
The **Reorder columns** node lets you change the order of the columns in a file. 

By maintaining a standardized and consistent column order in the files, you ensure that the data can be easily exported into the inventory system without manual adjustments or errors.


<div class="admonition admonition-warning"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z" /></svg></div><div class="admonition-body"><div class="admonition-content">

This node can be used only with CSV files.

</div></div></div>


## Node configuration
---
1. To use this node in a data transformation rule, go to **Automation Hub > Data Transformation > New transformation**. 
2. Click **Add input**.
3. Select the file you want to transform and confirm by clicking **Apply**.  
    You can find more information about adding input in the ["Data Input" node](/docs/automation/data-transformation-and-imports/transformations-and-data-operators/data-input) article.
4. Add the **Reorder columns** node.  
5. Open its settings by clicking the node.
1. Click **Add rule**.
2. From the **Include** dropdown list, define if you want to create a rule which includes (the **these** option) the columns or excludes (the **all except these** option) the columns which meet the conditions defined in the rules.  
    <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/node-config-include.png" class="large" alt="The Include option"><figcaption>The Include option</figcaption></figure>
1. Select columns to include/exclude (according to the **Include** option from the step before) from reordering in one of the following ways:
    - **Select column** - from the dropdown list, you can select the columns to be included or excluded from the transformation.
    - **Add condition** - you can create a dynamic condition which columns must meet to be reordered; for this purpose, you can use logical operators such as contain, starts with, ends with, and so on.  

    
   <div class="admonition admonition-important"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

   You can't combine dynamic conditions with the **Include all except these** option.

   </div></div></div>


    For further instructions, select one of the tabs below, depending on the option you have chosen in step 3.

    
   <div class="content-tabs" data-tab-group="tabgrp-1278">
   <div class="tab-buttons"><button class="tab-button" data-tab-id="tabgrp-1278-0" data-tab-group="tabgrp-1278" data-tab-active="true">Select column</button><button class="tab-button" data-tab-id="tabgrp-1278-1" data-tab-group="tabgrp-1278">Add condition</button></div>

   <div class="tab-panel" data-tab-id="tabgrp-1278-0" data-tab-group="tabgrp-1278" data-tab-active="true">

   4. From the dropdown list, select the first column that will be moved to a different position.
   5. To change the position of more columns, click <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/dt-plus-icon.png" alt="Adding new icon" class="icon" > icon.

   </div>

   <div class="tab-panel" data-tab-id="tabgrp-1278-1" data-tab-group="tabgrp-1278">

   <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/merge-column-dynamic.png" class="medium" alt="Define condition option"><figcaption>Define condition option</figcaption></figure>

   1. Select one of the following logical operators to define the conditions which the column name must meet:
       - **Ends with** - The column name must end with the phrase you enter.
       - **Starts with** - The column name must start with the phrase you enter.
       - **Contain** - The column name must contain the phrase you enter.
       - **Not contain** - The column name can't contain the phrase you enter.
       - **Regex** - The column name must match the regular expression you enter.

   </div>
   </div>


2. From the **Move columns** dropdown list, select one of the options below.  
    If more than one column is selected/meets the rule, the columns will be in an order of adding it to the conditions, see [example of use](#example-of-use).
    - **To the beginning** - Selected columns/Columns which meet the conditions will be moved to the beginning of the file (far left). 
    
      <div class="content-tabs" data-tab-group="tabgrp-1279">
      <div class="tab-buttons"><button class="tab-button" data-tab-id="tabgrp-1279-0" data-tab-group="tabgrp-1279" data-tab-active="true">Input</button><button class="tab-button" data-tab-id="tabgrp-1279-1" data-tab-group="tabgrp-1279">Output</button></div>

      <div class="tab-panel" data-tab-id="tabgrp-1279-0" data-tab-group="tabgrp-1279" data-tab-active="true">

      <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/original-position.png" class="full" alt="The original position of the column in an example file"><figcaption>The original position of the column in an example file</figcaption></figure>

      </div>

      <div class="tab-panel" data-tab-id="tabgrp-1279-1" data-tab-group="tabgrp-1279">

      <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/position-beginning.png" class="full" alt="The column reordered according to the To the beginning option"><figcaption>The column reordered according to the To the beginning option</figcaption></figure>

      </div>
      </div>

    - **To the end** - Selected columns/Columns which meet the conditions will be moved to the end of the file (far right).
    
      <div class="content-tabs" data-tab-group="tabgrp-1280">
      <div class="tab-buttons"><button class="tab-button" data-tab-id="tabgrp-1280-0" data-tab-group="tabgrp-1280" data-tab-active="true">Input</button><button class="tab-button" data-tab-id="tabgrp-1280-1" data-tab-group="tabgrp-1280">Output</button></div>

      <div class="tab-panel" data-tab-id="tabgrp-1280-0" data-tab-group="tabgrp-1280" data-tab-active="true">

      <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/original-position-end.png" class="full" alt="The original position of the column in an example file"><figcaption>The original position of the column in an example file</figcaption></figure>

      </div>

      <div class="tab-panel" data-tab-id="tabgrp-1280-1" data-tab-group="tabgrp-1280">

      <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/position-end.png" class="full" alt="The column reordered according to the To the beginning option"><figcaption>The column reordered according to the To the end option</figcaption></figure>

      </div>
      </div>

    - **Before column** - Selected columns/Columns which meet the conditions will be placed immediately before (to the left) the selected column.
    
      <div class="content-tabs" data-tab-group="tabgrp-1281">
      <div class="tab-buttons"><button class="tab-button" data-tab-id="tabgrp-1281-0" data-tab-group="tabgrp-1281" data-tab-active="true">Input</button><button class="tab-button" data-tab-id="tabgrp-1281-1" data-tab-group="tabgrp-1281">Output</button></div>

      <div class="tab-panel" data-tab-id="tabgrp-1281-0" data-tab-group="tabgrp-1281" data-tab-active="true">

      <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/original-position-before.png" class="full" alt="The original position of the column in an example file"><figcaption>The original position of the column in an example file</figcaption></figure>

      </div>

      <div class="tab-panel" data-tab-id="tabgrp-1281-1" data-tab-group="tabgrp-1281">

      <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/position-before.png" class="full" alt="The column reordered according to the Before column option"><figcaption>The column changes its place before the email column </figcaption></figure>

      </div>
      </div>

    - **After column** - Selected columns/Columns which meet the conditions will be placed immediately after (to the right) the selected column.
    
      <div class="content-tabs" data-tab-group="tabgrp-1282">
      <div class="tab-buttons"><button class="tab-button" data-tab-id="tabgrp-1282-0" data-tab-group="tabgrp-1282" data-tab-active="true">Input</button><button class="tab-button" data-tab-id="tabgrp-1282-1" data-tab-group="tabgrp-1282">Output</button></div>

      <div class="tab-panel" data-tab-id="tabgrp-1282-0" data-tab-group="tabgrp-1282" data-tab-active="true">

      <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/original-position-after.png" class="full" alt="The original position of the column in an example file"><figcaption>The original position of the column in an example file</figcaption></figure>

      </div>

      <div class="tab-panel" data-tab-id="tabgrp-1282-1" data-tab-group="tabgrp-1282">

      <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/position-after.png" class="full" alt="The column reordered according to the After column option"><figcaption>The column reordered according to the After column option</figcaption></figure>

      </div>
      </div>

    - **To position** - Selected columns/Columns which meet the conditions will be moved according to the position you indicate by a number.
    
      <div class="content-tabs" data-tab-group="tabgrp-1283">
      <div class="tab-buttons"><button class="tab-button" data-tab-id="tabgrp-1283-0" data-tab-group="tabgrp-1283" data-tab-active="true">Input</button><button class="tab-button" data-tab-id="tabgrp-1283-1" data-tab-group="tabgrp-1283">Output</button></div>

      <div class="tab-panel" data-tab-id="tabgrp-1283-0" data-tab-group="tabgrp-1283" data-tab-active="true">

      <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/original-position-position.png" class="full" alt="The original position of the column in an example file"><figcaption>The original position of the column in an example file</figcaption></figure>

      </div>

      <div class="tab-panel" data-tab-id="tabgrp-1283-1" data-tab-group="tabgrp-1283">

      When you set the position to **0**
      <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/to-position.png" class="full" alt="The column reordered according to the To position option"><figcaption>The column reordered according to the To position option</figcaption></figure>   

      When you set the position to **1**
      <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/to-position-1.png" class="full" alt="The column reordered according to the To position option"><figcaption>The column reordered according to the To position option</figcaption></figure>  

      When you set the position to **2**
      <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/to-position-2.png" class="full" alt="The column reordered according to the To position option"><figcaption>The column reordered according to the To position option</figcaption></figure>

      </div>
      </div>

3. To add more rules, click **Add rule**, and repeat steps 2-4.  
    Rules are joined with the **AND** logical operator.
5. Confirm by clicking **Apply**.


### Handle errors

You can define what to do with failed values (for example, as a result of Jinja rendering or in other cases) in cells where data type modification failed.
In the **Handle incomplete data** section, select one of the following options:
- **Skip row if error occurred** - It omits the row when an exception occurs.
- **Skip if result is null or empty string** - It omits rows with empty strings and `null` (which may be the result of rendering Jinja)
- **Stop further transformation** - The transformation stops at the row with an error. The data before the line that caused the error is transformed (and imported if the transformation rule is used in the Data Transformation node).
- **Insert null if error occurred** - Wrong values are replaced with `null`. If you use such a transformation for the import of profiles, the existing value of an attribute is cleared and replaced with the `null` value.
- **Insert empty string if error occurred** - Wrong value is removed and the cell remains empty.

## Example of use

In the following example, we will organize columns in a file so email, name, surname columns will be at the beginning of the file.
The initial state of the file is as follows: 

<pre><code class="language-plaintext">marketing_agreement,country,surname,name,email
false,USA,Doe,John,john.doe@example.com
true,USA,Smith,John,john.smith@example.com
false,England,Williams,Jane,j.williams@example.com
true,Wales,Brown,Rachel,rachel.brown@example.com</code></pre>


1. As the first node, add **Data Input**.  
2. In the configuration of the node, upload a file on which you want to perform data transformation.
3. As the next node, add **Reorder columns**.  
4. In the configuration of the node:  
    1. Click **Add rule**.  
    2. Leave the **Include** option at default (**these**).
    3. Click **Select columns**. From the dropdown list, select the columns in the preferred order, in this case it will be: **email**, **name**, **surname**.  
    <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/reorder-columns-example.png" class="small" alt="Selected columns"><figcaption>Selected columns</figcaption></figure>   

    4. Set **Move columns** option to **To the beginning**.  
        **Result**: 
        <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/automation/_gfx/reorder-columns-example-output.png" class="medium" alt="Output of the transformation"><figcaption>Output of the transformation</figcaption></figure>  
    5. Confirm the settings by clicking **Apply**.  
