Build data table and get min date value

Hello,
I have create data table and finally writing to excel report. I need minimum from excel sheet.
Could you please to help or advise. How to completed the process.
|Data soruce||

Data soruce
Item Expdate
1000000 28/02/2022
1000000 28/02/2023
1000000 28/02/2024
1000001 28/02/2022
1000004 28/02/2023
1000004 28/02/2024
Expect
Item Expdate
1000000 28/02/2022
1000001 28/02/2022
1000004 28/02/2023

Thank you so much.

Hi @pjaiphak

This can be done using the LINQ.

(From r In inputDT 
Group By i = r("Item") Into grp=Group
Let md = CDate(grp.Min(Function (gr) Date.ParseExact(gr("Expdate").ToString, "dd/MM/yyyy", Nothing)))
Select outDt.Rows.Add({i, md.ToString("dd/MM/yyyy")})).CopyToDataTable

image

Attached xaml file

Min Date.xaml (8.5 KB)

Hi @pjaiphak

You can complete your process by below steps.
1.Sort data source order by Expdate ascending.
2.Create a collection tor record items in data source.
3.For each row in data source.
4.If the item of current row dosen’t exist in collection, then add to output data table and add to collection.
5.Output your output data table.

@kumar.varun2 Very advanced but it’s helpful. I’m got message “String is not recognized as a valid datetime”. Because i’m wrong type of variable. After change sting to object it’s fine.
Thank you so much.

@wusiyangjia Thanks guy for advise. I will try this solution.

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