UiPath Activities

Compare Numeric Values

The example below explains how to compare the numeric values from two different columns of a .csv file. It presents activities such as Read Range, Excel Application Scope, or Write Cell. You can find these activities in the UiPath.Excel.Activities package.

This example compares the values from columns A and B and writes the results in a new column C. In the C column, = means that the numbers are equal, A means that the first number is greater, and B means that the second number is greater.

This is how the automation process can be built:

  1. Open Studio and create a new Process named by default Main.

Note:

Make sure to add the .csv file that you want to use in the project folder. You can also use the file we provided by downloading the example available at the bottom of this page.

  1. Drag a Flowchart in the Workflow Designer.
    • Create the following variables:
Variable Name
Variable Type
Default Value

existingColumns

WorkbookApplication

-

RowIndex

Int32

1

  1. Drag an Excel Application Scope activity in the Flowchart and connect it to the Start Node.
    • Double click on the Excel Application Scope activity to open it.
    • In the Properties panel, add the path of the .csv file in the WorkbookPath field, in this case, columns.xlsx.
    • Select the check boxes for the AutoSave, CreateNewFile and Visible options. The robot is now allowed to create a new Excel workbook, to automatically save all the changes made to it and to open the Excel file in the foreground while performing actions on it.
    • Add the variable existingColumns in the Workbook field.
  2. Select the Do sequence inside the Excel Application Scope activity and create the following variable:
Variable Name
Variable Type
Default Value

dtColumns

System.Data.DataTable

-

  1. Drag an Excel Read Range activity inside the Do sequence.
    • In the Properties panel, add the name "Sheet1" in the SheetName field.
    • Add the variable dtColumns in the DataTable field.
  2. Add a For Each Row activity below the Read Range activity.
    • In the Properties panel, add the variable dtColumns in the DataTable field.
  3. Drag an If activity inside the Body sequence of the For Each Row activity.
    • Add the expression cint(row(0))=cint(row(1)) in the Condition field. The cint method converts the values extracted from the table to the Int32 format, enabling the comparison of the two numbers.
  4. Drag a Write Cell activity to the Then section of the If activity.
    • In the Properties panel, add the expression "C" + RowIndex.ToString in the Range field and the variable "Sheet1" in the SheetName field.
    • Add the expression "=" in the Value field.
  5. Drag an If activity to the Else section of the If activity.
    • In the Properties field, add the name If values in the DisplayName field.
    • Add the expression cint(row(0)) > cint(row(1)) in the Condition field.
  6. Add a Write Cell activity in the Then field of the If values activity.
    • In the Properties panel, add the expression "C" + RowIndex.ToString in the Range field and the variable "Sheet1" in the SheetName field.
    • Add the expression A in the Value field. This value is written in column C if the first number is greater than the second one.
  7. Add a Write Cell activity in the Else field of the If values activity.
    • In the Properties panel, add the expression "C" + RowIndex.ToString in the Range field and the variable "Sheet1" in the SheetName field.
    • Add the expression B in the Value field. This value is displayed in column C if the first number is smaller than the second one.
  8. Place an Assign activity under the If activity, inside the body of the For Each Row activity.
    • Add the variable RowIndex in the To field and the expression RowIndex+1 in the Value field. The expression RowIndex+1 causes the row index to increase every time a loop is performed, until the end of the table is reached.
  9. Run the process. The automation process analyze the data and create a new column with the compared values.
     
     
    Download example

Compare Numeric Values


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.