# Getting the largest value from a data table?

Hi all,

I am working on a bot which scrapes a list and assigns them into their own rows in a data table.
As you can see, the values have year dates at the end and I want to essentially take the value with the largest date year and disregard the rest. Of course, we can get these years with row(0).ToString.Split(" "c).Last.

My question is: how do I filter these results to take the one with the largest year? I want to then assign it to its own string variable. I’m quite new to this, so it is a bit alien to me aha.

Thanks a lot!

Hello,

Can you try the below expression after Extract data Activity.

Use assign and assign the value to String Variable
MyDT.AsEnumerable.Max(Function(x) x(0).ToString.Trim.Split(" "c).Last).ToString

1 Like

Ok sure, I can do that - what is this assign actually doing and will I need to do more after?

I would guess it is just assigning the largest year, is that right?

Hi @dr1992 ,

Assuming that you would require the whole cell value which has the Highest Year, then you could try the below Query :

``````value = DT.AsEnumerable.OrderByDescending(Function(x)Cint(If(Split(x(0).ToString).Last.Trim.IsNumeric,Split(x(0).ToString).Last.Trim,"0"))).First.Item(0).ToString
``````

Here, `value` is variable of type String and `DT` is your Input datatable.
Let us know if this is not the expected output.

1 Like

what is this assign actually doing and will I need to do more after? - This assign will give you the largest year value from the x number of rows in your DT as per your problem statement.

Assign : LargeYear(String) = MyDT.AsEnumerable.Max(Function(x) Cint(x(0).ToString.Trim.Split(" "c).Last)).ToString

1 Like

Got it in one! Much appreciated.

1 Like

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