Guys,
I would like to seek for you help in getting the last records considering if it is one or more records and identical.
For example:

in this example they have identical type or entity, so I would be getting all.
In this example:

There are four records and the last three are identical, so I would be getting the last 3.
In this example:

In this example, there are 8 records and the last record is V2024 with no other identical records. So only 1 record to be recorded.
Kindly help me how I am going to produce this kind of scenarios. Attaching the three sample source file for your reference.
Kamen