Please see this link, I believe that you have to register the function max before using it in a model.
max