Aggregate functions such as SUM, AVG, and MAX can only appear in SQL statements and within certain statements you use in the context of a report body. They are not supported in ordinary expressions in program statements. You might be able to write an application-specific function to form this aggregate function on your data; however, you must name it something else because names such as SUM, AVG, and MAX are reserved words.