Sum earnings of the same employee

Asked

Viewed 38 times

0

I’m trying to sum up all the earnings of an employee (cumulative sum), but I’m not getting it. The code is following:

function teto() {    
  var ss = SpreadsheetApp; //seta a planilha 
  var planilhaAtiva = ss.getActiveSpreadsheet(); //torna-a ativa
  var abaAtiva = planilhaAtiva.getActiveSheet(); //seta a aba ativa

  for (var i = 2; i < 10; i++) {
    var cpf = [i][3];
    var valor = [i][11];

    if (cpf = cpf+1) {
      valor = valor + (valor + 1);
      abaAtiva.getRange(i,13).setValue(valor); 

    }
  }
}

Explaining: I have a column with numbers grouped from several employees, and another column with the value of the commission q it receives. If the Cpf of a line equals the Cpf of the bottom line, it does the sumveja a tabela exemplo aqui. It must make this sum as long as the Cpfs are equal, and put this value in a new column - C, SOMA.
If it is not equal, I do not want it to add up to the previous one, but to start a new sum with the new set of values of the same Cpf.

  • 1

    You need to put two equal in if. Also, the condition is wrong. It should be: if(cpf == [i+1][3]) Another thing is that the syntax is wrong too. put [i][3] is incorrect. I don’t know this library, but it should be: abaAtiva[i][3]. Soon: if(cpf == abaAtiva[i+1][3])

  • That’s right. It’s not pure javascript, but googleappscript, gas, and uses that notation.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.