Sum of Specific value in column

How to Sum of Specific value in column ???

Input:

image

@rajmoin136

Try this:

dt.AsEnumerable.Sum(Function(x) CDbl(x("Amount").ToString.Trim))

Sum of Specific value in column:

(
From row In dt1
Group row By a = row("Cname") Into grp = Group
Let Sum = grp.Sum(Function(x) CDbl(x("Amunt").tostring.trim))
Select dt2.
Rows.Add({a,sum})
).CopyToDataTable
1 Like

Hi @rajmoin136

→ Use the Read range workbook activity to read the excel and store in a datatable called dt.
→ Then use the Assign activiy to write the below linq expression,

- Assign -> SumofAmount = dt.AsEnumerable.Where(Function(X) Not (String.IsNullOrEmpty(X("Amount").ToString) AndAlso String.IsNullOrWhiteSpace(X("Amount").ToString))).Sum(Function(Y) Double.Parse(Y("Amount").ToString))

→ SumofAmount is the Double datatype variable. It stores the sum of the Amount column values.

Hope it helps!!

@rajmoin136

Please specify your requirement properly.You want to sum the entire Amount column or You want the data by grouping the Names volumn and then you want that sum

if you want to sum the Amount column then Use this linq query

Sum Datatype:Double

sum=dt.AsEnumerable().Sum(Function(row) If(IsNumeric(row("Amount").ToString), Convert.ToDouble(row("Amount")), 0))

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