How to divide and concatenate data table values through LINQ?

Hi Experts,

Hope you all are well.
I need your help on below use case.
I have input as

Required Output -

  • For Coumn B result, i want to divide column B by 100
  • For column D result, i want to append hyphen in Column C value

Please suggest Linq Query only.
Test.xlsx (8.9 KB)


have a look on the expression property of a datacolumn
Maybe a more straighforward way instead of LINQ
After adding the computed columns you can

  • take needed cols with dt.DefaultView(…
  • rename the cols

But this is related to scrapping, i just want calculation on the same column.

not related to scraping it is done on a datatable.You also asking for a datatable, right?

yeah that’s correct , i have downloaded that xaml but i don’t find anything useful.

I just need a single Linq, if you have please share it.

then you was very fast to RnD

  • Add Datacol - Amount 2
  • set Expression - “Amount / 2”
    check result

LINQ is not allways the prefered choice, Rough Prototype

dtTarget = dtData.Clone

(From d in dtData.AsEnumerable
let a = (ConvertToDouble(d(Amount))/ 100).toString(“F2”)
let r = d(“Reason”).toString & " - "
Let ra = new Object(){d(0), a, d(2), r}
Select dtTarget.Rows.Add(ra)).CopyToDataTable

1 Like

I have already achieved this through adding new columns and have it’s expression and then putting back to same column.

I am looking for something where i can get directly calculated values from single linq.

Not sure if this can be possible.

refer post above for rough linq suggestion

1 Like

Thanks, i will try to execute this.

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