Hello community,
Maybe this is very simple but I've looked at it for hours and losing my mind slowly so need to ask support.
What I need is to remove duplicates based on the reference to only have 1 record per reference but I need to keep the line that has comments and not just plain remove and keep the first one. If for the same reference, there are multiple lines with comments, I'd keep the one that has comments and highest age on the other column.
If multiple lines exist and no comments, I'd keep the highest age - but again, there could be duplicates there also so I need to keep only 1.
The comments can all be differently generated which also creates problems there.
Anyone fancy having a crack at it? 
| References | Counterparty Name | Latest Comment Text | Age |
| 55207225 | Jack Sparrow | | 0 |
| 55207225 | Jack Sparrow | | 4 |
| 55207225 | Jack Sparrow | | 5 |
| 55207324 | Jack Sparrow | | 5 |
| 55207324 | Jack Sparrow | | 5 |
| 55207324 | Jack Sparrow | | 0 |
| 89819654 | Jack Sparrow | | 192 |
| 90024782 | Persona J | | 7 |
| 90024782 | Persona J | | 12 |
| 91453297 | John Smith LTD | | 6 |
| 91453297 | John Smith LTD | | 14 |
| 91453297 | John Smith LTD | Client signed Please verify. | 39 |
| 91472861 | Music House LTD | Client signed Please verify….. | 6 |
| 91474819 | John Smith LTD | | 6 |
| 91474819 | John Smith LTD | Client signed Please verify. | 34 |
| 91485774 | John Smith LTD | | 6 |
| 91485774 | John Smith LTD | | 11 |
| 91485774 | John Smith LTD | | 14 |
| 91485774 | John Smith LTD | Client signed Please verify. | 45 |
| 91485774 | John Smith LTD | Client signed Please verify…... | 45 |
| 91485774 | John Smith LTD | Client signed Please verif---- | 34 |
| 91521718 | Jane Doe Inc. | No comment | 101 |
| 91539944 | ABC Corp | To be seen | 684 |
| 91544027 | XYZ, SA | | 0 |
| 91544027 | ABC Corp | Client signed Please verify. | 45 |
| 91544027 | ABC Corp | Client signed Please verify. | 13 |
| 91544027 | ABC Corp | NCR | 181 |
| 91544027 | ABC Corp | | 242 |
| 91544027 | ABC Corp | | 669 |
Thanks,
Marcos