Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
How do I set a calculated column in apps script similar to pandas?

I am trying to set a new calculated column based on values of two other columns. The condition is: whenever I insert new data in columns C and D, the column E should be calculated as "=C/D".

This would be the equivalent of this in pandas:

df['new']= df['C']/df['D']

but I do not know if JS supports this no-iteration feature Pandas offers

I tried this but nothing happens:

function sample(){
  var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
  var range=sheet.getRange('E2:E20000')
  for (i=0; i<range.length; i++){
    if (i==''){
      i.setFormula(`=${C[i]/D[i]}`);
    }
    else {
      pass
    }
  }
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can setFormula over the entire column like this:

var range=sheet.getRange('E2:E20000')
range.setFormula("C2/D2")

This is similar to setting conditional formatting. The top left of the range is all that matters. Everything else is relative. See my answer here.

about 4 years ago · Juan Pablo Isaza Report

0

Try this:

function sample() {
  const ss = SpreadsheetApp.getActive()
  const sh = ss.getSheetByName('Sheet2');
  const sr = 2;
  const rg = sh.getRange(2,1,sh.getLastRow() - sr + 1,5);
  const vs = rg.getValues();
  let cold =vs.map((r,i) => {
    r[4] = `${"=C" + Number(i + sr) + "/D" + Number(i + sr)}`;
    return [r[4]];
  });
  sh.getRange(sr,5,cold.length,cold[0].length).setFormulas(cold).setNumberFormat("#,##0.00");
}

setFormulas

setNumberFormat

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!