Find the Maximum value in a Datatable column

Hi,

I’m stuck and need some help. I have a Datatable and I want to get the highest value in Column-1. Is there a way I can do this? Btw, I’m using C#.

Thanks

Hi,

Can you try the following expression? this returns max value as double type

 dt.AsEnumerable().Max(r => Double.Parse(r["Column-1"].ToString()))

If there is non-numeric value (including empty), we need to add expression to filter it.

Regards,

we would recommend to let us know the datatype of the column value. lets assume doube

YourDataTableVar.AsEnumerable.Max(x => Convert.ToDouble(x["ColName"].ToString())

Also have a look here:

Thank you for this. Would I put this in an Assign activity?

They’re 5 or 6 figure integers

Hi @paulparkes

  1. Drag and drop an Invoke Code activity into your UiPath workflow.
  2. In the properties panel of the Invoke Code activity, create the following arguments:
  • dt (Argument direction: In, Argument type: DataTable)
  • columnName (Argument direction: In, Argument type: String)
  • maxResult (Argument direction: Out, Argument type: Double)
  1. In the Code property of the Invoke Code activity, enter the following C# code:

maxResult = Convert.ToDouble(dt.Compute(“MAX([” + columnName + “])”, “”));

Hope it helps!!

Regards,

Convert.ToInt32 method

Hi,
If you need assign the result to variable, yes as the following.

if you want to assign it to int32 varaible. the following will work.

dt.AsEnumerable().Max(r => Int32.Parse(r["Column-1"].ToString()))

Regards,

Thanks for this. I’m now seeing this message:
image

How do I resolve this message?

Thanks

Hi,

Can you try the following step?

First, save the xaml file.
Next, close UiPath Studio.
Then restart UiPath Studio.
Re-open the project. then probably automatic recovery will start.

Regards,

Thank you so much! :slight_smile:

1 Like

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