Excel group rows by duplicate cell value. Afterwards, in column J use this formula.