Re: Replacing partner ID with the parent partner ID if available
From the beginning you load all the fields from the Facts to FactsStageXYZ and a big synthetic key is resulting so that;s why you need to put the "temptest" field. You could Qualify the fields you want to take from the Facts table to your new FactsStageXYZ.
if NewPartnerKey is the new key you want to use then before renaming it you could drop the old %PartnerKey or raname it so you don;t get the Error. Also i think you can write like this the left join:
if(len(PartnerParentId)>0, PartnerParentId, %PartnerKey) as %PartnerKey
I really don;t understand why you are load the facts again in in the FactsStageXYZ...