Delete rows below the last entry of a value in a data table

Hello all,

I am quite new to the UIPath environment and also to coding and now I need your help because I just can’t get on with my problem. I am trying to solve the following in UIPath:

I read a *.csv file into a DataTable, then I have to delete all lines below the line with the last “SB” entry. There can be rows with other values above the rows with “SB” and below the rows with “SB” as well. The value “SB” is in the first column.

I hope it is understandable. I have attached an image of the CSV data, here the last 7 rows would be deleted accordingly.

Tanks a lot and have a good day
Hendrik

image

Hi @hendrik.berger

Welcome to forum

As of my understanding you need to select only rows having value CH and SB right ??
others have to be eliminated

Hi @Robinnavinraj_S ,

yes correct only CH and SB.

your current data sample would serve the condition filter on CH, SB
we can do it with the Filter DataTable Activity

But if a new Dataset will have other Values above the last SB, then the implementation will differ from requirement: delete all rows below of last SB

Implementation of Delete all rows below last SB (minimal implementation)

Assign acitvity:
LHS: idxLast | DataType: int32
RHS:
yourDataTableVar.asEnumerable.ToList.FindLastIndex(Function (x) x(0).toString.Trim.Equals("SB"))
it will return -1 when no SB was found

Assign Activity:
LHS: dtFiltered | DataType: DataTable
RHS:
yourDataTableVar.asEnumerable.Take(idxLast + 1).CopyToDataTable

Hi,

thanks a lot, the filter DataTabel Activity works. I also tried the delete below last SB but I get the following errors:

image

image

Any idea

greetings
Hendrik

sorry my bad. Please refer to corrected statement above

Hi,

Thank you very much, both solutions work now.

Greetings
Hendrik

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