I have csv data want to update last row value in first row

I have csv data want to update last row value in first row
But condition is
1.ID and State are same
2.If ID is same but state are different then dont change only chane when both are same
3.Please check the screenshot Input and output

  1. Read CSV

    • Input: Path to the CSV file
    • Output: dataTable (DataTable variable)
  2. Assign: lastRow (DataRow variable) = dataTable.AsEnumerable().LastOrDefault()

  3. Assign: idToMatch = lastRow(“ID”).ToString()

  4. Assign: stateToMatch = lastRow(“State”).ToString()

  5. For Each Row (row) in dataTable
    6. If (row(“ID”).ToString() = idToMatch) AND (row(“State”).ToString() = stateToMatch)

    • Then:
      • Assign: row(“ColumnToUpdate”) = lastRow(“ColumnToUpdate”)
      • Note: Replace “ColumnToUpdate” with the actual column name that you want to update.
  6. Write CSV

1 Like