For your scenario it would be easier to add index field to the repeating section and then query the last record using max() function. To ensure that the last record always has the highest index number assign initial value of that "index" field using max() function also.