Help on LINQ GroupBy, Max and Min

Hi @Marian_B

Try this

image

dt_Out=

(
	From row In dt_Input.AsEnumerable()
	Group row By k=row("Id").ToString.Trim
	Into grp=Group
	Let mindr = grp.OrderBy(Function(gr) gr("Date 1")).First()
	Let maxdr = grp.OrderByDescending(Function(gr) gr("Date 2")).First()
	Let d1 = mindr("Date 1")
	Let d2 = maxdr("Date 2")
	Let amt1 = mindr("Amount 1 ")
	Let amt2 = maxdr("Amount 2")
	Select dt_Input.LoadDataRow({k, d1, d2, amt1, amt2}, True)
).CopyToDataTable

Please refer the xaml file

LINQ_GroupByMultipleConditions.xaml (5.6 KB)

1 Like