Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138221

How to get separate sums per each separate column by Google Script. Unfortunately, my code doesn't work

$
0
0

enter image description here

I want to get sums of numeric values for each separate column in the range. What I do wrong?

  function countNutrients(){

  var sh = SpreadsheetApp.getActiveSheet();
  var lastcol = sh.getLastColumn(); //Get last column
  var lastcolval = sh.getRange(1, 1, 1, lastcol).getValues();
  var lastrowval = sh.getRange("C1:C").getValues(); //Trick to get last row
  var lastrow = lastrowval.filter(String).length;   //
  var sumvalues = sh.getRange(2, 14, lastrow, lastcol).getValues();
    (typeof sumvalues === 'number' ? "" : sumvalues);
    Logger.log(sumvalues);
    for (var j = 13; j < lastcolval.length ; j++) {
       var sumcolumnval = sh.getRange(2, [j], lastrow);
       var sum = 0;
       for (var i in sumcolumnval[0]) {
       var sum = sumvalues[0][i] + sum;
     }
     return sum
     Logger.log(sum);
  }
  return sumcolumnval

}

Columns on the screenshot and 65 more

enter link description here

CSV example


Viewing all articles
Browse latest Browse all 138221

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>