That part has a problem. You divide the day of the month by 31 (which gives a value from 0 to 1) then you subtract it from 31 giving you a number always from 30 to 31.

Without having any idea what you are really trying to do, I would guess that should be

(1- datepart (d,( getdate()))/31)

So it's still scaled from 0 to 1.