Last and 2nd last occurance of a value for an excel

Hi,

I want to find the last occurrence of a value in an excel using datatable activities

Example:image

I want to search for index of last and 2nd last occurrence for banglore which is in city column

Hi,

The following expression returns array of 0-based index which is City=“Bangalore”.

arrInt32 = dt.AsEnumerable.Where(Function(r) r("City").ToString="Bangalore").Select(Function(r) dt.Rows.IndexOf(r)).ToArray

Then

arrInt32.Last

returns index of the last.

arrInt32(arrInt32.Count-2)

returns index of the 2nd last.

Regards,

1 Like