How to Get second largest value in Column

hi,
i have an Excel Sheet columns → Name, city , Salary. in salary how to find second largest value in that column ?
can any one help about this .
image

1 Like
  1. First sort the data table(ascending order) on salary column by using sort data table activity
    https://docs.uipath.com/activities/docs/sort-data-table
  2. Then use the below expression to get the second highest salary
varDt.rows(varDt.rows.count-3)(2).ToString

Give a try on

YourDataTableVar.AsEnumerable.Select(Function (x) Convert.ToInt32(x("Salary"))).OrderByDescending(Function (i) i).ElementAt(1)
1 Like

thanks for reply .its working fine but the count is count -2 is correct . ->varDt.rows(varDt.rows.count-2)(2).ToString

You can adjust it after testing but logic will be same…If you are reading without header then 3 if you have considered headers then 2…

Just test with both and whichever is giving correct value go ahead with that

1 Like

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