Subtraction of the two columns

Hi All,
Good afternoon.
Can anyone help me to do the subtraction operation in uipath.
i.e I wanna subtract two different column in a excel and write the result in another column.
Column3= Column1-Column2.

I am trying like this:

  1. Reading excel file(DT1).
  2. Passed the DT1 in for each loop.
  3. Get row item(Column1)
  4. Get row item(Column2)
  5. In an assign activity I am displaying the output like Column3= Column1-Column2
    but I am getting an error like in the attachment.
    Please someone help me on this

Best Regards,
Naveen S


And my workflow looks like:

Hi @HeartCatcher

Try like method below.

  1. Reading excel file(DT1).
  2. Passed the DT1 in for each loop.
  3. Inside the loop assign
    Currentrow(“Result”)=Cint(currentrow(“Credit”).tostring)-Cint(Currentrow(“Debit”).toString)
    4.Outside the loop write range Dt1.

Regards

Hi @pravin_calvin,
Thanks for the reply, I tried as you suggested but I am getting an error as in the attachment

Add a condition that if that cell is empty it wont do this activity

Hi @Gresilda_Balla,
Thanks for the response I tried I am getting error like


Please help me out on the same

we can defensive handling empty cell value with following:
Cint(“0” & currentrow(ColNameOrIndex).tostring)

1 Like

Sorry didn’t get you

please show us the implementation from this: Column3= Column1-Column2

Credit-Debit.xaml (18.3 KB)
please find

there are severeal things to check and maybe to adopt

crosscheck if name or index is properly used for referencing the column
after opening the xaml we saw:
grafik
(maybe an opening issue on quick review)
and do see following when click on Name
grafik

give a try on Cint(“0” & Credit.toString) - Cint(“0” & Debit.toString)

In general:

  • using assign activity for getting row’s col value like below allows us to get more control on what we get as the variable type is set by us and the retrieval statement is done by us:
    grafik

Just start with these modifications and lets see what you will get on next run

So adopt it if needed

@ppr,

As you said I have checked the index in get row item its correct.
after that what you said I didn’t can you please explain a bit

run it check please

Cint(“0” & Credit.toString) - Cint(“0” & Debit.toString)


I tried your method but I am getting the error

Credit-Debit.xlsx (14.7 KB)
Please find the excel which I am using to achieve the subtraction.

0-3790 string is not value that can be converted into an int. So your data quality is not on a state that the impementation can run or there is a bug in the implementation that creates this string

we can convert 1,2,3 …100 but not number-number …

Issue occured on this part: Cint(“0” & Credit.toString) - Cint(“0” & Debit.toString), right?

Check the statement on your implementation again

you have to convert that value into integer use Cint function

@HeartCatcher
Defensive 0 Trick was confused by negative values

Variables:

MainFlow:

Credit = CurrentRow(“LCY_AMOUNT”).toString
iCredit = if(isNothing(Credit) OrElse String.IsNullOrEmpty(Credit.ToString), 0, CInt(Credit))

Find some starter help here:
Credit-Debit.xaml (12.6 KB)

1 Like