Count last records depending on its value
I have a one to many relationship between table A and table B (which is the child table). In table B i have a text field called "status". There could be many records and the "status" is changing between "on" and "off" (only these two values are available).
Now I want to count the records in the layout of table A where the last related records in table B in the field "status" are "on". How I can do this? I tried to do it with a calculation field in table B without success:
Count(status) AND GetNthRecord ( status; Get ( RecordNumber ) - 1 ) = "On"