fix bug in max value on joined fields

I did not change the indentation for an easier review. 

Once reviewed I'll fix the useless scope and add a commit.