Skip to content

Instantly share code, notes, and snippets.

@jsdbroughton
Created September 7, 2017 17:15
Show Gist options
  • Save jsdbroughton/c19c1d630a94a3f6b44e88f93440b92c to your computer and use it in GitHub Desktop.
Save jsdbroughton/c19c1d630a94a3f6b44e88f93440b92c to your computer and use it in GitHub Desktop.
Google Sheets Custom Function that returns an sum for all rows in a range or array.
/**
* Returns a sum for each row of a given array.
* @param {range} range The range or array to sum.
* @customfunction
*/
function ROW_SUM(range) {
if (!range.map) {
range = [[range]]; // deal wih single cell ranges.
}
return range.map(function(row){
return row.reduce(function(a, b) { return a + b; }, 0);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment