google-sheetsgoogle-apps-script

Trouble getting log function to work in a custom function for Google sheets


Ok the error says:

#ERROR! TypeError: Math.Log is not a function (Line 11)

Here is the code now:

/**
 * Find Lot Midpoint value. (Start, End, Total, Slope)
 * @param {number} Start The Start QTY of lot.
 * @param {number} Last The Finish QTY of lot.
 * @param {number} Total The Total QTY of lot.
 * @param {number} Slope The Slope of the Curve.
 * @return The calculated cost change.
 * @customfunction 
 */
function Midpoint(Start, End, Total, Slope) {
  return (((1 / (1 + (Math.Log(Slope) / Math.Log(2)))) * ((Last + 0.5) ** (1 + (Math.Log(Slope) / Math.Log(2))) - (First - 0.5) ** (1 + (Math.Log(Slope) / Math.Log(2))))) / Total) ** (1 / (Math.Log(Slope) / Math.Log(2)));
}

Solution

  • Ok so, to summarise: