If - Condition , If two column value are equal , sum up the corresponding row

Hello All,

I have a challenge where if “invoice” & “Batch” are having the same data values, then “Amount” should be added
input :
image

output:
image

Thank you

@Yugal_Raju

You can try this

dt = dt.AsEnumerable.GroupBy("function(x) x("invoice").ToString).Select(function(g) dt.LoadDataRow({g.key.ToString,g.Sum(function(y) y("Amount").ToString).ToString,g.First()("Batch").ToString},False)).CopyToDataTable

Cheers

I’m getting warning That “g” is not declared or inaccessible

@Yugal_Raju

Please check the above modified formula…i gave x and g together corrected now

Cheers

So instead of g i should put x ?

Sorry I’m a little confused.

@Yugal_Raju

I modified the formula in the above comment itself…use the new one directly

cheers

I’m getting this error:

@Yugal_Raju

Missed a set of brackets…modified above please check

Cheers

Hi @Yugal_Raju ,

please check this query

(
From row In dt_Input.AsEnumerable
Group row By a= row("Invoice").ToString.Trim,b=row("Batch").ToString.Trim Into grp=Group
Let s=grp.Sum(Function(x) CDbl(x("Amount").ToString.Trim))
Let ra= New Object(){a,s,b}
Select dt_Output.Rows.Add(ra)
).CopytoDataTable

GroupBy_2Columns_And_Sum.xaml (8.4 KB)

Regards,

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