I am trying to create a formula to calculate Net Promoter Score on Google Sheets. I have the formula working but only when I specify the exact range. My issue is that this specific sheet will grow with data over time and I do not want to have to keep reselecting the range. What I want to do is select the entire row and just let it auto-update the NPS score. My issue with this approach is every empty cell is considered a zero which is screwing up my percentages. How can I make my function ignore the empty cells???
Here is my attempt:
/**
This is a custom formula that calculates the Net Promoter Score.
@customFunction
*/
function NPS(numArr) {
var detractors = new Array();
var passive = new Array();
var promoters = new Array();
var i = 0;
for (i = 0; i < numArr.length; i++) {
if (isNaN(numArr[i])) {
console.log(numArr[i]);
} else {
if (numArr[i] >= 9) {
promoters.push(numArr[i]);
} else if (numArr[i] === 7 || numArr[i] === 8) {
passive.push(numArr[i]);
} else if (numArr[i] <= 6) {
detractors.push(numArr[i]);
}
}
}
var promoPercentage = promoters.length / numArr.length;
var detractorsPercentage = detractors.length / numArr.length;
return (promoPercentage - detractorsPercentage) * 100;
}
numArrparameter come from? - Andrew Lohr