WOW. That just work nicely.
I was trying to do something very similar but i was always getting an "Invalid dimension" message even when in the expression box everything seems ok.
My code was
= if(FirstSortedValue(Aggr(Max(IdHistory) ,IdProject), -IdHistory) = 2, ProjectName)
Very similar to yours but with the Aggr and FirstSortedValue changed.
Could you please tell me what i was doing wrong?