Out of curiosity, how do you know if a code goes from stage 1 to 2, etc...?
The same code will appear twice in the dataset, 3 times for stage 3, etc.
Your questions are tough to answer in Tableau v8,
but much easier to do so in an upcoming v9 (currently in beta).
Level-Of-Detail (LOD) calculations -- new in v9 -- make it much simpler.
Please find the attached workbooks (both v8 and v9).
Hope this helps.