I have seen this question and have tried the code suggested: Adapting ESRI ArcGIS API for JavaScript Feature Layer With Selection sample for use in Configurable Map Viewer (CMV)
But I have been unable to get it to work. I also want to change the result from the sum to the average.
Here is my error report from chrome development tools