Excel duplicates and marked as zero value, remain the bottom value per document number

Hi All,

Let me know if we can achieve without using for each row activity for below result. Since the data rows are more than millions and it will take time.
Result: write 0 for the duplicates but remain the same for the last row per document


Looks solveable with a LINQ