# How can I calculate the average of a sum of list column data, excluding zero values?

I have 10 users who have each ranked 10 items (1-10) in a list. I am using REST to post their rankings to a second list called my 'Rankings List'. This rankings list has 10 items in it for each user, corresponding to their rankings (so the items will have matching titles in the source list along with the number the user assigned as their rank of the item). I was tasked with creating a view that would display like below. Essentially a tally of the votes/rankings for each item:

• Item 1 Title: 5 votes total
• Item 2 Title: 3 votes total
• etc. on down through ten

The problem is, some users put zero values for some items. My script below is accomplishing the view above but I need to display the AVERAGE vote count for each item based on how many people entered a value other than zero (zeros should not be accounted for in the averages). I am new to JS and SP and have been trying for hours to figure this out after searching multiple time but I can't seem to get it. Any insight would be very very much appreciated! Thanks so much!

`````` var myNewArray = [];

for(var i = 0;i < objArrayThree.length;i++){
if(objArrayThree[i].Rank != 0){
myNewArray.push(objArrayThree[i]);
}
}

var overRank = "";
var summary ={};
summary = groupBy(myNewArray);
var title = objArray[i].Title ? objArray[i].Title : "";
var arr = Object.entries(summary);
arr.sort(function(a,b){
return a[1] - b[1];
});
var arr_with_rank = arr.map((data, index) => [data[0], index+1]);  //this is now ranked 1 - whatever

arr_with_rank.forEach(function(entry){
if(title == entry[0]){
overRank = entry[1];
}
});

function groupBy(items){
var result= {};
var sum;

\$.each(items, function(index, item) {
sum = result[item.RequestName] || 0;
result[item.RequestName] = sum + item.Rank;
});
return result;
}
``````