Getting the difference of 2 columns where the first 3 rows are not included

Good Day,

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.

SampleExcel.xlsx (9.4 KB)

Asking for your help and guidance. Thank you.

Best regards,
Robert Russell Monsalud

Hi @RobertRussell_Monsalud ,

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 :

1 Like

Hello @RobertRussell_Monsalud

  1. Use an “Excel Application Scope” activity to work with Excel.
  2. Set the WorkbookPath property in the “Excel Application Scope” to your Excel file path (e.g., “your_file_path.xlsx”).
  3. 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).
  4. 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.

Thanks & Cheers!!!

1 Like

Hi @Kartheek_Battu,

Apologies for the very late reply. I encountered this kind of error:

May I know the possible solution for this? Thank you.

Best regards,
Robert

Hi @supermanPunch,

Apologies for a very late reply. I’m currently working on it. Thank you so much for the idea. I really appreciate it.

Best regards,
Robert

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.