String to double error

Dear Friends, I am using the below code
Dt_billnotlodged = (From row in out_dt_final1021.AsEnumerable.Where(Function(x) x (“Remarks”).tostring.tolower.contains(“bill not lodged”))
Group row by a =row(“Trim”) into grp =group
Let xsum =grp.sum(Function (x) CDbl(x(“Final Reportable in INR”). tostring.trim))
Select Dt_billnotlodged.rows.add({a,xsum})). copytodatatable
When I am using this I am getting error as conversion from string “” to type double is not valid.

Can anyone help me how to resolve this, please

HI,

How about the following expression?

(From row In out_dt_final1021.AsEnumerable.Where(Function(x) x ("Remarks").tostring.tolower.contains("bill Not lodged"))
Group row By a =row("Trim") Into grp =Group
Let xsum =grp.sum(Function (x) If(Double.TryParse(x("Final Reportable In INR").tostring.trim,New Double),Double.Parse(x("Final Reportable In INR").tostring.trim),0))
Select Dt_billnotlodged.rows.add({a,xsum})). copytodatatable

Regards,

Hi @Yoichi thanks for quick response I have a doubt will this give default value as 0

The error shows there is empty string and failed to convert to double type.
So, i think it’s no problem if we handle empty string as 0 because it’s Sum function.
If you have any concern, can you share it?

Regards,

|Column 1 | Column 2 | Column 3 | Column 4|
|Remark | Trim | Final Reportable in INR| Date|
| Bill not lodged|123 | 0 |21-10-2022 |
| Bill compared| 456 | 56 |21-10-2022 |
| Bill complete| 543 | 76| 21-10-2022|
|Bill not lodged | 567 | 0 |21-10-2022 |
| Bill compared| 987| 54|21-10-2022 |
| Bill not lodged| 566 | 34 | 21-10-2022|
My excel looks something like this here I want Trim and Final Reportable in INR values

Hi @0bb4628e217fd43ac86ac9294

=> Build Data Table:
image
Output-> Dt_biklboylodged

=> Read Range Workbook
image
Output-> out_dt_final1021

=> Use below syntax in Assign:

Dt_billnotlodged = (From row In out_dt_final1021.AsEnumerable().Where(Function(x) x("Remark").ToString().Contains("Bill not lodged"))
                   Group row By a = row("Trim") Into grp = Group
                   Let xsum = grp.Sum(Function(x) If(Double.TryParse(x("Final Reportable in INR").ToString().Trim(), 0.0), CDbl(x("Final Reportable in INR").ToString().Trim()), 0.0))
                   Select Dt_biklboylodged.Rows.Add({CInt(a), CInt(xsum)})).CopyToDataTable()

=> Write Range Workbook Dt_billnotlodged back to excel
image

Sequence16.xaml (9.8 KB)

Hope it helps!!

Hi,

How about the following?

Sample
Sample20240426-2.zip (3.8 KB)

Regards,

Got it your issue is in line number 1 or one, when BOT is reading this file it taking the first row as header and the second column 2 contain string (Trim)and value (134).

you need to delete the first row and make your data look like below read the first row as header

that why it is not able to convert the string to Double

Note : I cant see any empty row in sample file

@0bb4628e217fd43ac86ac9294 I hope it will solve your issue