Custom UDAF functions - First, Last and Max rows