ERROR IN FUCTION GROUP BY

Hi all,

I have a workflow with this function:

dtPivot(is a var datatable) = (From d In dtPv.AsEnumerable
Group d By k=d(“Soc.”).toString.Trim, k2= d(“Codici iva”).ToString.Trim, k3=d(“Registro”).ToString.Trim,k4=d(" M").ToString.Trim Into grp=Group
Let cs1 = grp.Sum(Function (x) Convert.ToDouble(x(" Imp. base imponibile").toString.Trim))
Let cs2 = grp.Sum(Function (x) Convert.ToDouble(x(" IVA vendite").toString.Trim))
Let cs3 = grp.Sum(Function (x) Convert.ToDouble(x(“IVA vend.da vers”).toString.Trim))
Let ra = New Object(){k,k3,grp.First()(“CI”),k2,k4,cs1,cs2,cs3}
Select dtPv.Rows.Add(ra)).CopyToDataTable

where dtPv is a datatable

I have been using this workflow for over a month and have never received any errors. Now it shows me the following error

Any suggestion ?

Could you support?

Thanks in advanced

Regards,
S.

1 Like

Hey @salvatore.quimi

This should be most probably from the Convert.ToDouble steps where the string you are trying to convert may not be in proper double format.

Better to check the source dt either from source file or the debug panel to see if it has the valid format of double values.

Hope this helps

Thanks
#nK

hi @Nithinkrishna,

I try to convert.todouble, but not works. Can you give me an example?

Regards,
Salvatore

1 Like

Hey @salvatore.quimi

Nope. What I meant is you have some convert.todouble present in your code already which is where the exception would have occured…

Because there is a chance the string you try to convert as double using the above function may not be a double…

Hope you get this.

Thanks
#nK

Hi @salvatore.quimi ,

Could you try Updating your Query to the Below and Check :

(From d In dtPv.AsEnumerable
Group d By k=d("Soc.").toString.Trim, k2= d("Codici iva").ToString.Trim, k3=d("Registro").ToString.Trim,k4=d(" M").ToString.Trim Into grp=Group
Let cs1 = grp.Sum(Function (x) Convert.ToDouble(If(x(" Imp. base imponibile").toString.Trim.IsNumeric,x(" Imp. base imponibile").toString.Trim,"0")))
Let cs2 = grp.Sum(Function (x) Convert.ToDouble(If(x(" IVA vendite").toString.Trim.IsNumeric,x(" Imp. base imponibile").toString.Trim,"0")))
Let cs3 = grp.Sum(Function (x) Convert.ToDouble(If(x("IVA vend.da vers").toString.Trim.IsNumeric,x(" Imp. base imponibile").toString.Trim,"0")))
Let ra = New Object(){k,k3,grp.First()("CI"),k2,k4,cs1,cs2,cs3}
Select dtPv.Rows.Add(ra)).CopyToDataTable

There is an Additional Check on the column values to decide if it is numeric value or not, if Numeric, then we should be able to use the column value for converting to a Double.

Let us know if you are still facing issues.

2 Likes

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