Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

378
Vistas
Google Apps script that replicates vlookup and Countif formula together

I'm looking for some help on trying to combine a formula in excel to apps script function.

Below image shows what result is expected and how I have incorporated that result using excel formula combining COUNTIF and VLOOKUP. It will be really helpful if someone can suggest me how I can incorporate it using apps script in Google sheets without using this formula.

Image for the expected result using 2 tables and the formula used to get that output

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'm not 100% certain on what you're looking for, but I have come up with a script that completes what I believe you're asking.

/** @OnlyCurrentDoc */

function getMetric2() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('Sheet1') //change to the name of your sheet

  var uniqueRange = sheet.getRange('A13:A19');
  var uniqueIds = sheet.getRange('A13:A19').getValues(); //change range to the keys in the final output table
  var findKey = sheet.getRange('A3:A5').getValues(); //change range to table 1 unique keys

  var lastKey;

  for(var i = 0; i < uniqueIds.length; i++) {
    //i = row
    for(var j = 0; j < uniqueIds[i].length; j++) {
      if(lastKey == uniqueIds[i][j]) break;
      //j = column
      var trueRow = 13+i; //change constant to the row number that var uniqueIds starts at
      var row = findKey.findIndex(row => row.includes(uniqueIds[i][j]));
      var col = findKey[row].indexOf(uniqueIds[i][j]);
      var foundRow = row+3; //change constant to the row number that var findKey starts at
      
      let metric2 = sheet.getRange('C'+foundRow).getValue();
      sheet.getRange('C'+trueRow).setValue(metric2);
      lastKey = uniqueIds[i][j];
    }
  }
};

This formula iterates through the IDs from the Final Output table, finds them in Table 1, and returns the corresponding Metric2 value for each.

Linked below is the sheet I used to create and test this. Edit permissions are on, and you should be able to click the button to see the script run.

https://docs.google.com/spreadsheets/d/1eJFm5YpL18X5hqZ5tKnHgT5T60dKMSq18bWqibriRqk/edit?usp=sharing

Please let me know if you have any issues with this, or if it wasn't what you were looking for.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda