Find Max value from datatable

Try as shown in the above image and let me know.

Tried same as this, getting error…

Trans.xlsx (9.9 KB) GetMaxValueFromDatarow.xaml (7.0 KB)

Check with these files, I am getting correct answer and compare with your files.

Trans.xlsx (9.9 KB)
My excel is like sheet2 of above excel…

@Manish540,

I have modified the linq query in the first assign statement as the following to have only the column names contains “Col” as the keyword.

row.Table.Columns.Cast(Of DataColumn)().Where(Function(c) c.ColumnName.Contains("Col")).ToDictionary(Function(c) c.ColumnName, Function(c) row(c))

Thank You:smiley:

Sorry for disturbing you now i m using datatable as,
“InputDataTable1.AsEnumerable.Select(Function(row) row.Table.Columns.Cast(Of DataColumn)().Where(Function(c) c.ColumnName.Contains(“AE1”)).ToDictionary(Function(c) c.ColumnName, Function(c) row(c)))”- In first assign.

In next assign,Im using
“RowColumns.Aggregate(Function(x, y) If(Convert.ToInt32(x.Values) >Convert.ToInt32(y.Values), x, y)).Key.ToString” - But Im getting error in this assign…

Error is “Key is not a member of ‘…Dictionary(of string,of object)’'”

@Manish540,

Kindly check the query, In the xaml which I have provided and using in my machine has only x.Value but in your query it looks x.Values ,

Compare these two and find out the mistake, still it is working with the column name contains “AE1”

RowColumns.Aggregate(Function(x, y) If(Convert.ToInt32(x.Values) >Convert.ToInt32(y.Values), x, y)).Key.ToString

'My Query:
dictColumns.Aggregate(Function(x, y) If(Convert.ToInt32( x.Value) >Convert.ToInt32( y.Value), x, y)).Key.ToString

If I use x.Value, Im getting error…
Now I have used Datatable in first assign, not the row…

@Manish540,
You need if for each column right, I didnt notice that first assign query.

Please tell me what exactly you are looking for.

I’m looking for the largest among the Columns and its name, But now I’m using the datatable not the datarow…
But its not getting me error when I used x.Values and .Keys…

GetMaxValueFromDatarow.xaml (9.6 KB)

Check this one, modified few things and added a new dictionary to add the result from all the rows.

Here is an detailed article on it :slight_smile:
# Find The Max And Average Value From DataTable – In UiPath

Regards,

Based on the max value from the datatable how to get the complete colume values.
Exp:- like Ename,ID,salary
In that we find max salary. based on that how to get complete column values(ex:Ename,ID,Salray) values.

dt.select("Salary=dt.AsEnumerable().Average(Function(row) Convert.ToInt32(row("Salary")))").CopyTodatatable()

Or

dt.Select("Salary=MAX(Salary)").CopyToDataTable()

Regards,
Arivu