How to get value based latest date?

Hi,

I have a data like this and with my expected output :

image

I tried to do in query with MAX(DATES) function but it’s not working… In UiPath, it will only get 1 value only. If I have 1000 data like this, how to get the value based on latest date? Thanks :slight_smile:

Here is the excel file :

Dummy.xlsx (9.0 KB)

hey,
you can use sort Data table
please follow this workflow
Sample2.xaml (9.4 KB)

Thanks,
Rounak

It’s as expected, but what if I have 10.000 data that are needed to be sorted like this? Because I also have to remove the unnecessary dates (in picture, 2 june and 13 june need to be removed to avoid redundant data)

Hi,

Hope the following helps you.

dt = dt.AsEnumerable.GroupBy(Function(r) DateTIme.Parse(r("Sent Date").Tostring)).OrderBy(Function(g) g.Key).Last().CopyToDataTable()

Sample20220714-2.zip (8.8 KB)

Regards,

Hi,

I tried your solution and it works only for 1 customer ID, I tested with 3 customer ID like this :

And it only returns 1 value instead of 3.

Here is the file :

Dummy.xlsx (9.5 KB)

Hi,

How about the following?

dt = dt.AsEnumerable.GroupBy(Function(r) r("Customer ID").ToString).SelectMany(Function(g) g.GroupBy(Function(r) DateTIme.Parse(r("Sent Date").Tostring)).OrderBy(Function(g2) g2.Key).Last()).CopyToDataTable()

Sample20220714-2v2.zip (16.0 KB)

Regards,

1 Like

Working as expected. Thank you very much Mr. Yoichi !!

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