Skip to content

Instantly share code, notes, and snippets.

@benlcollins
Last active March 4, 2022 21:17
Show Gist options
  • Select an option

  • Save benlcollins/5ba425b759aefd77d4469f612fda56d8 to your computer and use it in GitHub Desktop.

Select an option

Save benlcollins/5ba425b759aefd77d4469f612fda56d8 to your computer and use it in GitHub Desktop.

Revisions

  1. benlcollins renamed this gist Mar 4, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. benlcollins created this gist Mar 4, 2022.
    28 changes: 28 additions & 0 deletions Code.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    /**
    * 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);
    }