I'm trying the first time to use google sheets and the script to sum a column of values and place the sum in the first free cell with a date.
Unfortunately I get a string and not the Sum I'm expecting.
Do you have any clue?
Thanks
KR
function sommami() {
var foglioAssets = SpreadsheetApp.getActive().getSheetByName('Assets');
Logger.log(foglioAssets)
var colonnaP = foglioAssets.getRange('P2:P100');
Logger.log(colonnaP);
var array = colonnaP.getValues()
Logger.log(array)
var somma = array.reduce(function(a,b) {
return a+b});
Logger.log(somma);
var foglioHistoricalNW = SpreadsheetApp.getActive().getSheetByName('HistoricalNW');
Logger.log(foglioHistoricalNW)
var primaRigaLibera = foglioHistoricalNW.getRange('A:A').getValues().length + 1;
Logger.log(primaRigaLibera)
var data = Utilities.formatDate(new Date(), "GMT", "dd/MM/yyyy");
Logger.log(data)
foglioHistoricalNW.getRange('A' + primaRigaLibera).setValue(data);
foglioHistoricalNW.getRange('B' + primaRigaLibera).setValue(somma);
}
17:15:04 Notifica Esecuzione avviata 17:15:04 Informazioni Sheet 17:15:04 Informazioni Range 17:15:04 Informazioni [[596.38], [17515.15], [29.79], [369.02], [], [6829.2], [12082.0], [14991.0], [], [300000.0], [32000.0], [18500.0], [], [19971.99], [35820.104140799995], [], [-162547.23], [-48500.0], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []] 17:15:04 Informazioni 596.3817515.1529.79369.026829.21208214991300000320001850019971.9935820.104140799995-162547.23-48500 17:15:04 Informazioni Sheet 17:15:04 Informazioni 6.0 17:15:04 Informazioni 19/02/2024 17:15:05 Notifica Esecuzione completata
I've tried multiple things but nothing worked

Logger.log()within your function used forreduce()to confirm the numbers it is adding up. It should work. Make sure they are actual number format and not pieces of text...