When a person joins a congregation after it has commenced, the first complete unit that he gets to offer as a part of the congregation should be considered as the first unit of that individual’s prayer. The additional units that are made up following the completion of congregational prayers should be offered according to their respective sequence in that individual’s prayer.
For example, if a person misses the first two units of Maghrib prayer and joins in the last (3rd) unit after the imam’s salaam, he should pray two additional units the first of which will be really the second unit of his prayer and he should as such sit down to do the witnessing (tashahhud) after the prostrations (sajdah).