Group larger files using invoke code

Hi devs, please assist I am grouping using C# but on larger files the code fails and throws out of memory exception, how do we rewrite pls: Here’s the code

if (dt.Rows.Count>0)
{
output = dt.AsEnumerable()
.GroupBy(dr => dr.Field(“NO”))
.Where(g => g.Count() < 2)
.SelectMany(g => g)
.CopyToDataTable();
}
else
{
Console.WriteLine(“Debit Is Empty”);
}
}

1 Like

Hey @RPA-botDev

Approx how many rows do you have?

Thanks
#nK

1 Like

How much memory do you have?
Divide the tasks.
it seems that SelectMany() and CopyToDataTable() function require lots memory.

First, get list distinct “NO” field,
then iterate, grouping, selectMany
finally append to table.

1 Like

Hi Nithin Krishna, I have approximately 200000 rows

Okay what do you want to actually do - I mean if you show us the input and expected output.

1 Like

Book1.xlsx (9.4 KB), the result returns the grouped values based on condition