Division Formula_LINQ

Hi Expert,

I have an excel file and i need to divide by 2 the columns of IGST_CGST in all data rows and the result will come to each data rows in the result column. How can achieve this by LINQ. (Attached input file)
Thanks in advance
Division.xlsx (9.0 KB)

@Balachander_Pandian

Please try this in invoke code and send dt as in/out argument

Dt.AsEnumerable.ToList.ForEach(Sub(r) r("ColumnName") = (cdbl(r("ColumnName").ToString)/2).ToString)

Also if column type is double then you can use expression as well in assign

Dt.Columns("TargetColumnName").Expression = "[Gstcolumn]/2"

Cheers

1 Like

@Balachander_Pandian

(From row In Dt.AsEnumerable()
                   Let IGST_CGST = Convert.ToDouble(row("IGST_CGST"))
                   Select Dt.Clone().Rows.Add(row.ItemArray.Take(2).ToArray().Concat({IGST_CGST / 2}).ToArray())).CopyToDataTable()

image

1 Like

Hi @Balachander_Pandian

resultDataTable= dtInput.Clone()

resultDataTable= (From row In dtInput.AsEnumerable()
      Let IGST_CGST = CDbl(row.Field(Of Double)("IGST_CGST"))
      Let Result = IGST_CGST / 2
      Select resultDataTable.Rows.Add(row.Field(Of Double)("Sno"), IGST_CGST.ToString(), Result)).CopyToDataTable()

resultDataTable is of DataType System.Data.DataTable


Hope it helps!

1 Like

You can try with this:
Output = Enumerable.Range(0, number1).Count() / number2

1 Like

Hi @rlgandu Thank you

1 Like

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