Trying to Group By DataTable based upon multiple columns

image

DTwithDuplicates.AsEnumerable().GroupBy(function(x) {x(“Product Name”).ToString, x(“Product ID”).ToString}).Select(function(g) g.CopyToDataTable)

Trying above expression and assigning to variable of <IEnumerable>

But its not working as intended and giving below output:
image

@Yoichi @loginerror @Pablito

Hi,

Can you try the following expression?

DTwithDuplicates.AsEnumerable.GroupBy(Function(r) Tuple.Create(r("Product Name").ToString, r("Product ID").ToString)).Select(Function(g) g.CopyToDataTable).ToList

Regards,

1 Like

Also have a look here:

1 Like

@Yoichi : great Thanks a lot it works

Is there a Linq way to created derived column let say amount = Price*QTY from existing 2 columns Price and QTY without iterating for loop.
Thanks in advance

in that case we often can use the expression property of a datacolumn

1 Like

Let me try this

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