Skip to content

Instantly share code, notes, and snippets.

@benlcollins
Last active March 4, 2022 21:17
Show Gist options
  • Save benlcollins/5ba425b759aefd77d4469f612fda56d8 to your computer and use it in GitHub Desktop.
Save benlcollins/5ba425b759aefd77d4469f612fda56d8 to your computer and use it in GitHub Desktop.
Google Tables (Area 120) test column calculation in Apps Script
/**
* MULTIPLIES two number column values and saves into a column
* @param tableId - id of the table to read row data from
* @param rowId - id of the row to read data from and update
* @param lowValue - low value from Table
* @param highValue - high value from Table
* @param feeValue - fee value from Table
*/
function multiply(tableId, rowId, lowValue, highValue, feeValue) {
// Get the row of data from the table, make sure it exists or abort
const row = Area120Tables.Tables.Rows.get('tables/' + tableId + '/rows/' + rowId);
if (!row) { console.error('Row does not exist'); return; }
// Calculate average
const average = (parseFloat(lowValue.replace(',', '')) + parseFloat(highValue.replace(',', ''))) / 2;
// Calculate estimated revenue
const estRevenue = average * parseFloat(feeValue.replace(',',''));
// update the row values
row.values['Average'] = average;
row.values['EstRevenue'] = estRevenue;
// send data back to Tables
Area120Tables.Tables.Rows.patch(row, row.name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment