Check out the attachment and let me know if it is not the desired result.
In you script using group function (max) without group by clause might be the problem. Group by sequence would automatically result in distinct results.
Hope this answers your question.
Test v0 02.qvw 136.0 K