First of all, you are able to make use of relevant functions available in the database you are using for your data (.....if your data is coming from a database). If you are using Oracle, for example, you can simply use their analytical functions in your source. However, if this must be implemented in Talend, it can be done as in this mini tutorial.....
https://www.rilhia.com/quicktips/quick-tip-compare-row-value-against-value-previous-row
This is rather limited, but prevents the need to load all of the data into memory. If you are happy with doing that, you can use the tHash components to achieve this.