Here is a quick script that performs the data table updating you want.
Names default to here(1);
dt=current data table();
// Create the RoomLeave column and initialize it
If(Try(dt:RoomLeave<<get name,"")!="", dt<<delete columns("RoomLeave"));
wait(.2);
dt<< New Column("RoomLeave", set each value(0));
// Find the last staydate and the Arrival Room for each RecordID
dtsumm = dt << Summary(invisible,
Group( :RecordId ),
Max( :StayDate ),
Max( :ArrivalRoom ),
Freq( "None" ),
Weight( "None" ),
statistics column name format( "column" )
);
// Change the ArrivalRoom to the RoomLeave
dtsumm:ArrivalRoom << Set Name("RoomLeave");
// Cleanup the data table to keep only the columns needed
dtsumm << delete columns("N Rows");
// Update the original data table with the Leaving data
// Matching on the RecordID and the last staydate
dt << Update(
With(dtsumm ),
Match Columns( :RecordId = :RecordId, :StayDate = :StayDate )
);
// Delete the summary data table
close( dtsumm, nosave );
Jim