cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
j_bonnouvrier
Level III

Unable to delete columns in a datatable

Good morning,

 

I am currently writing a script in order to extract data from an Excel file and format the data table.

A typical exemple is enclosed to this post.

My concern is that I cannot delete the last columns (6th column to the end). Do you have any clue on what  the problem is?

 

Thanks in advance for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Unable to delete columns in a datatable

Deleting columns changes the dimensions of the table which can cause a forward going loop to fail. Try to delete from the end.

 

dt = Current Data Table();
n = N Col(dt);
// Delete last six columns columns, starting from the end
For(i = n, i > n - 6, i--,
    dt << delete columns(Column(i))
);

// This should also work: delete very last column six times
For(i = 1, i <= 6, i++,
    dt << delete columns(Column(N Col(dt)))
);

View solution in original post

2 REPLIES 2
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Unable to delete columns in a datatable

Deleting columns changes the dimensions of the table which can cause a forward going loop to fail. Try to delete from the end.

 

dt = Current Data Table();
n = N Col(dt);
// Delete last six columns columns, starting from the end
For(i = n, i > n - 6, i--,
    dt << delete columns(Column(i))
);

// This should also work: delete very last column six times
For(i = 1, i <= 6, i++,
    dt << delete columns(Column(N Col(dt)))
);
j_bonnouvrier
Level III

Re: Unable to delete columns in a datatable

Problem fixed, thanks!