Hello, I cannot sum up values in my excel sheet. I want to change the output to a value so i can sum. But i keep getting Assign: Conversion from string “” to type ‘Integer’ is not valid.
We cannot convert an empty string. But we can handle it defensive, when it would occur
Hi @helpplease
-
Read Range: Read the Excel sheet and store the output in a DataTable variable (e.g., dtData).
-
For Each Row: Iterate through each row of dtData.
- For each row in dtData:
- Assign: Use an “Assign” activity to check if the cell value is empty or null.
- Example:
- Left side: row(“ColumnName”)
- Right side: If(String.IsNullOrEmpty(row(“ColumnName”).ToString()), 0, Convert.ToInt32(row(“ColumnName”)))
- Example:
- Assign: Use an “Assign” activity to check if the cell value is empty or null.
- For each row in dtData:
-
Sum the values: Use the “Assign” activity to calculate the sum of the desired column.
- Example:
- Left side: sumVariable
- Right side: dtData.AsEnumerable().Sum(Function(row) Convert.ToInt32(row(“ColumnName”)))
- Example:
Regards,
Assign Activity:
mySum | Int32 =
(From d in YourDataTableVar.AsEnumerable
Let v = d(YourColumnNameOrIndex)
Let s = If(isNothing(v) OrElse String.isNullOrEmpty(v.toString.Trim), "0", v)
Let pchk = Int32.TryParse(s, nothing)
Let i = If(pchk, Int32.Parse(s), 0)
Select x = i).Sum()
km is string (variable type)
int_km is Int32 (variable type)
This is my problem.
My data table header are Name (left), Distance ran (left).
Both header are String.
sum → Int32 (variable type)
The double quotation that you have given in the Distance ran is giving you the error. Give the double quotes correctly. It will solve the error.
Hope it helps!!
Regards,
Hi @helpplease
Can you share input excel file if possible? It’s no problem if dummy data.
Regards,
As per the intial error we can see that the string is empty and you are trying to convert empty string to integer which will fail…as there is no equivalent integer for an empty string…
So either first filter on numeric value or use a if condition to check for number and then convert he remaining
If with km.IsNumeric
this will check if km is number or not
On then side use cint(km)
Cheers
Cheers
Hi, i managed to get the CInt to work, but my values got cut off.
The value saved from the top assign activity is 10.11 but after the second assign activity to convert it to Int, the value became 10
Cint converts the value to integer if you want it as double then use CDBL instead of Cint
cheers
km_Int is Int32 variable type
i don’t see “system.double”
Where can i find it?
You can find in the Variables panel click on the variable type if you not find there then click on browse for types then search there system.double. Click on it. @helpplease
Hope it helps!!
it worked, thank you!!
ok, thank you!!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.