What is the possible solution or work around if I am going to get the difference of 2 columns where in the first 3 rows, the value for the Difference column is the same with the Height column? Kindly see below the picture and attached xlsx file.
We could maybe use the index property of For Each Row to get the row indices currently being considered and with an If activity we should be able to identify if the row index is greater than 2, if Greater than 2 perform the Subtraction between the columns else, just Assign the Height Column value to the Difference Column.
Here Also, we assume that the Excel sheet is read as a Datatable and we are manipulating the datatable values. A Skeleton Sample would be something like below :
Use an “Excel Application Scope” activity to work with Excel.
Set the WorkbookPath property in the “Excel Application Scope” to your Excel file path (e.g., “your_file_path.xlsx”).
Inside the “Excel Application Scope,” add a “Read Range” activity to read data from the Excel file and store it in a DataTable (e.g., dtInput).
Next, use an “Assign” activity to calculate the “Difference” column in the DataTable. You can use this code in the Assign activity:
dtInput.AsEnumerable().ToList().ForEach(Sub(row, index)
If index < 3 Then
row(“Difference”) = row(“Height”)
Else
row(“Difference”) = Convert.ToDouble(row(“Height”)) - Convert.ToDouble(row(“Weight”))
End
This code calculates the “Difference” column based on your specified criteria.
5. Finally, add a “Write Range” activity to write the updated DataTable (with the “Difference” column) back to the Excel file.