Specified cast is not valid - when trying to retusn sum

I am trying to return sum of column “BROJ APLIKACIJA” from data table (all is printed well after extracting from excel)

image

but getting error “Specified cast is not valid”

I’m using
tabelaPlasiraniTotal.AsEnumerable().Sum(Function(r) r.Field(Of Double)(“BROJ APLIKACIJA”)).ToString

Hi @Olivera_Kalinic

Try this expression

(From d in dtData.AsEnumerable Where Not (isNothing(d("BROJ APLIKACIJA")) OrElse String.IsNullorEmpty(d("BROJ APLIKACIJA").toString.Trim)) Select v = CDbl(d("BROJ APLIKACIJA").toString.Trim)).Sum(Function (x) x)

Regards
Gokul

1 Like

DT.Asenumerable.sum(Function(r) CInt(“0”+r(1).Tostring))

1 Like

I tryed, but getting the error below

This one also returns error

image

DT.Asenumerable.sum(Function(r) CInt(“0”+r(1).Tostring)).Tostring

Try with this expression

(From d in dtData.AsEnumerable Where Not (isNothing(d(1)) OrElse String.IsNullorEmpty(d(1).toString.Trim)) Select v = CDbl(d(1).toString.Trim)).Sum(Function (x) x)

d(1) → Is the column index

Regards
Gokul

Thank you for your support, in the meanwhile I find solution by iterating through all table rows and making sum of wanted column items.