Hi How can i write LINQ query to sum all different excel columns data separately and paste the total below them

in excel i have four diff columns data

Please find sample data for u r reference

format excel.xlsx (8.4 KB)

You can use LINQ select to manipulate the data while returning it.

Take a look at Enumerable.Select Method (System.Linq) | Microsoft Learn

This example its a good one:

```
IEnumerable<int> squares =
Enumerable.Range(1, 10).Select(x => x * x);
foreach (int num in squares)
{
Console.WriteLine(num);
}
/*
This code produces the following output:
1
4
9
16
25
36
49
64
81
100
*/
```

Hi @T_Y_Raju

Try this

```
Dt.AsEnumerable().Sum(Function(row) row.Field(Of Double)("Amont1")).ToString
```

Regards,

that is only for 1 column how about other columns like Bill Tax Bill invoice no

Same like that only you have to change column names

For 1 column, i am given same you can try for other columns

```
Amount1=DT.AsEnumerable().Sum(Function(row) row.Field(Of Double)("Amont1")).ToString
```

```
"A"+(DT.RowCount+2).ToString
```

**Output:**

Regards,

for second column we have to write in the same query or different query

can u write how can we write for 2 columns

```
Amount1=DT.AsEnumerable().Sum(Function(row) row.Field(Of Double)("Amont1")).ToString
```

```
"A"+(DT.RowCount+2).ToString
```

```
Bill=DT.AsEnumerable().Sum(Function(row) row.Field(Of Double)("Bill ")).ToString
```

```
"B"+(DT.RowCount+2).ToString
```

**Output:**

Regards,

thank you very much for your help

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