When working with data tables in UiPath, there are scenarios where you might need to rearrange the columns. While UiPath offers several activities to manipulate data tables, using the Filter Data Table activity creatively can help you change column positions efficiently. In this blog post, we’ll walk you through the process step-by-step.

 Step 1: Setting Up Your Environment

Before we start, ensure you have UiPath Studio installed. Open a new project and add the necessary dependencies, such as UiPath.Excel.Activities if you’re working with Excel files.

image 13

 Step 2: Reading the Data Table

First, we need to read the data table. If your data is in an Excel file, use the Read Range activity to load it into a DataTable variable.

1. Drag and drop the Excel Application Scope activity.

2. Provide the path to your Excel file.

3. Inside the scope, use the Read Range activity and read excel template with table format below.

image 14
image 15

4. Set the output to a DataTable variable, e.g., `DtCustDetails`.

Step 4: Using the Filter Data Table Activity

Now, we’ll use the **Filter Data Table** activity to rearrange the columns.

  1. Drag and drop the **Filter Data Table** activity.
image 16
  • In the Input DataTable field, select your original DataTable, ` DtCustDetails `.
image 17

3. In the Output DataTable** field, select your new DataTable, e.g., `DtOutput`.

4. In the Columns tab, specify the columns to include in the new order.

For example:

– Add a new column in the Column Name field for each column you want to include.

– Set the Output Column Index to the new position of the column.

image 18

 Step 6: Writing the Data Back to Excel (Optional)

If you want to save the rearranged DataTable back to an Excel file:

1. Use the Write Range activity.

2. Provide the path to the new or existing Excel file.

3. Specify the DataTable variable, `DtOutput`, as the input.

Conclusion

Rearranging columns in a DataTable using the Filter Data Table activity in UiPath is a straightforward process. By following the steps outlined in this blog post, you can efficiently reorder your data to meet your requirements. This approach is particularly useful when working with complex data transformations and ensuring your data is structured correctly for subsequent operations.

Tagged in: