As in the operator if you compare two excel cells. I don’t understand what to write in the condition. The task is like this: “an employee in an Excel file marks the added new lines with a temperature in green if the deviation from the previous reading is no more than 1 unit, yellow for a deviation of no more than 3 units, red for a deviation of more than 3 units.” That is, I need to compare the lines and I don’t understand what to prescribe in the condition of the operator if.
I tried like this, but it gives an error: CurrentRow.Item+1>CurrentRow.Item
Hi @sazonov038 ,
i > 0 AndAlso Cdbl(CurrentRow(“ColumnName”)) > CDbl(InputDt(i - 1)(“ColumnName”))
Where i is the variable of index in for each row and InputDt is the data table you are using in for each row.
Hope this helps.
what is it Cdbl?
Convert to Double. Since your data will be a number, you can convert it to Double and compare.
i > 0 AndAlso Math.Abs(Cdbl(CurrentRow(“ColumnName”)) - CDbl(InputDt(i - 1)(“ColumnName”))) <=1
Then Green
i > 0 AndAlso Math.Abs(Cdbl(CurrentRow(“ColumnName”)) - CDbl(InputDt(i - 1)(“ColumnName”))) <=3
Then Yellow
i > 0 AndAlso Math.Abs(Cdbl(CurrentRow(“ColumnName”)) - CDbl(InputDt(i - 1)(“ColumnName”))) > 3
Red
Else
Nothing.
Math.Abs - Converts negative value to positive.
In this case only for first row, that is i=0 it goes to else
You can use Convert.ToDouble also instead of CDbl.
Hope it helps.
Hi @sazonov038
To compare two Excel cells in UiPath, you can use the “If” activity and an “Assign” activity to get the cell values. Here’s an example of how you can compare the temperature readings and assign colors based on the deviation:
- Use a “Read Range” activity to read the Excel file and store the output in a DataTable variable, let’s call it “dtReadings”.
- Use a “For Each Row” activity to loop through the rows in the DataTable.
- Inside the loop, use an “Assign” activity to get the previous and current temperature readings, like this:
- Assign prevTemp = Convert.ToDouble(row.Item(“Temperature”))
- Assign currentTemp = Convert.ToDouble(row.Item(“Temperature”).ToString)
- Then, use an “If” activity to compare the current and previous temperature readings and assign the appropriate color to the “Color” column, like this:
- If (currentTemp - prevTemp) <= 1, then assign “Green” to row.Item(“Color”)
- Else If (currentTemp - prevTemp) <= 3, then assign “Yellow” to row.Item(“Color”)
- Else, assign “Red” to row.Item(“Color”)
Note: Make sure that the “Color” column exists in the DataTable before running the above steps.
Regarding the error in your code, the syntax seems to be incorrect. To compare two cells, you can use the “>” operator, but you need to specify the column name and row index of each cell. Here’s an example:
- If (Convert.ToDouble(CurrentRow.Item(“Temperature”).ToString) - Convert.ToDouble(dtReadings.Rows(CurrentRow.Index-1).Item(“Temperature”).ToString)) <= 1, then assign “Green” to CurrentRow.Item(“Color”)