LINQ_SUM_DATAROWS

Hi Expert,

I have an excel table and i need sum two datarows.( i.e. Amt_Before_Tax +GST sum up value will come on Taxvalue column.) How to do achieve this by LINQ. Attached input file
LINQSUM.xlsx (9.0 KB)

@Balachander_Pandian

dtData.AsEnumerable().ToList().ForEach(Sub(row) row.SetField("TaxValue", Convert.ToDecimal(row("Amt_Before_Tax")) + Convert.ToDecimal(row("GST"))))

1 Like

Hi @Balachander_Pandian

Use the below vb in Invoke code activity,

For Each row As DataRow In inputDataTable.Rows
    Dim amtBeforeTax As Double = Convert.ToDouble(row("Amt_Before_Tax"))
    Dim gst As Double = Convert.ToDouble(row("GST"))
    row("TAXvalue") = amtBeforeTax + gst
Next

Check the below workflow for better understanding,

Input -
MicrosoftTeams-image (7)

Output -
MicrosoftTeams-image (8)

Hope it helps!!

@mkankatala Thank you Much

1 Like

Hi @Balachander_Pandian ,

Try this.

Input:
image

Output:
image

Code:

(From rows In dt.AsEnumerable
Let a = CDbl(rows("Amt_Before_Tax").ToString)+CDbl(rows("GST").ToString)
Select dt.Clone.Rows.Add({rows("sno").ToString,rows("Amt_Before_Tax").ToString,rows("GST").ToString,a.ToString})).CopyToDataTable

Workflow:
image

Xmal:
Sum.zip (1.4 KB)

Thanks,

It’s my pleasure… @Balachander_Pandian

Happy Automation!!

1 Like

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