WIth the correct relationship, you don't need any script. An auto-enter field option can enter the value from the previous record for that equipment. The trick is in setting up the correct match fields and sort order for a new occurrence of your table. This would not match value by the km fields--they won't have matching values.
A possible relationship is to match records by Equipment ID's and then to sort the related records in descending order by a date or time stamp field that auto-enters a creation
So, I've changed the relationship to ID Equip = ID Equip and ID Shif dif ID Shift.
Sort order descending, both, through creation date field.
The KM1 field is a calculated value field, with If (Get ( RecordNumber ) - 1 = 0; 0; GetNthRecord ( KM2; Get ( RecordNumber) -1))
Am I going somewhere? It returns "0".
If I use GetNthRecord ( KM2; Get ( RecordNumber) -1), it returns the value not from a previous ID Shift and not from the correspondent equipment, but from the previous row, on the same shift.
With a descending order specified as part of the relationship,
Try this reference to the related records
GetNthRecord ( RelatedTableOccurrencenamehere::KM12 ; 2 )
With that sort order and relationship, the first related record should be the same record, the next record, record number 2, should be the preceding record for that item of equipement.
Temporarily, set up a portal to that Tutorial: What are Table Occurrences? to make sure that the second portal row shows the record from which you need to copy data.
It worked! I only had to change GetNthRecord ( RelatedTableOccurrencenamehere::KM2 ; 2 ) to GetNthRecord ( RelatedTableOccurrencenamehere::KM2 ; 1 ).
Thank you so much