Rearranging columns in a DataTable

Hi,

I need to change the format of a DataTable by rearranging columns and including blank columns in-between. Can you help help me the process to do so.

PFA the old_csv and preferred_csv.

Hi @shrayud !
I donā€™t know why but I have an error when i try to unzip your folder.
Anyway, to add columns, you can use ā€œAdd DataColumnā€ activity and precise the index you want the column to be added and give it a dummy columnName
To change the position of the columns, I use an artisanal way: by using Filter datatable activity, and add all the columnNames at the column field in the wanted order. I am sure there is a better way, but for the time being itā€™s a clue :joy:
image

1 Like

For Rearranging the table columns you can use Set Ordinal method in the invoke code activity using the below code:

Dt.columns(ā€œyourcolumnnameā€).setordinal(5)

I just gave 5 as an example here.

1 Like

Hey thanks:

error BC30451: ā€˜dtCheckā€™ is not declared. It may be inaccessible due to its protection level. At line 1

This error is coming. dtCheck is my datatable

Oh sorryā€¦you have to use Invoke Method activity.

I will share the sample once I am back.

hi @shrayud ā€¦ Please find the sample belowā€¦

My Input:(Status column is 2 i.e. index 1 (index starts of 0)

image

Invoke Method ( here I gave, so that Status column will be moved to 0)

You can see the output in my first screenshot.

Hope this helpsā€¦

2 Likes

Thanks,

I also need to delete few columns like in your case:

[ID Status Value Date] It needs to be

[ID Date Value] I want to remove status column while rearranging; can I do so using Invoke activity

@shrayud - You can use ā€œRemove DataColumnā€ Activity and give ColumnIndex as 1 (in your case)ā€¦

or you can useā€¦ā€œInsert\Delete Columnsā€ inside excel app scope ā€¦and choose remove in the property and give the column positionsā€¦

1 Like

Thanks

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.