How can I add a total function?