Hey guys
I have a data table, which I have filtered to give me one column;
Column A
2010.79
2300.98
155.80
I want to get the sum of this column. How can I do this?
Hey guys
I have a data table, which I have filtered to give me one column;
Column A
2010.79
2300.98
155.80
I want to get the sum of this column. How can I do this?
FYI, I can’t find the “. AsEnumerbale” as a method to use on the datatable
hi,
please add the assembly reference to your xaml file(open xaml file using notepad)
System.Data.DataSetExtensions if not present then you will get .asenumerable() the you can use .sum()
Thanks
@Suzana_Joby Can you Check with this Expression :
DT.AsEnumerable.Sum(Function(a)Convert.ToDouble(a(“Column A”).ToString))
And if you get an Error on AsEnumerable, Check this Post :
Thank you @supermanPunch and @praneeth.peyyeti
Come up now.
But the expression results in error, “Input string was not in correct format”
I have checked the value of the column header and everything is spelt correctly.
Can you help pls?
@Suzana_Joby Can you check with this Expression, that error usually occurs when you have a null or a Space or if your number isn’t in the right format :
DT.AsEnumerable.Sum(Function(a)if(String.IsNullOrEmpty(a(“Column A”).ToString) or String.IsNullOrWhiteSpace(a(“Column A”).ToString),0,Convert.ToDouble(a(“Column A”).ToString)))
Hello @Suzana_Joby
you can try this,
(from r in DATABLENAME.AsEnumerable() Select Convert.ToDouble(r("COLUMNNAME"))).Sum()
Here replace DATATABLENAME with your dt name and COLUMNNAME with the column name in your Datatable
Thanks everyone!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.