Title: Execute Function in Calculated Field
Last modified: April 20, 2018

---

# Execute Function in Calculated Field

 *  Resolved [M C](https://wordpress.org/support/users/mcyger/)
 * (@mcyger)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/execute-function-in-calculated-field/)
 * I want to use a normsinv function within a calculated field, with the field calculated
   as:
    NORMSINV(fieldname1/1000000)
 * The function I’d like to include is:
 * function NORMSINV(p)
    { // Coefficients in rational approximations var a = new
   Array(-3.969683028665376e+01, 2.209460984245205e+02, -2.759285104469687e+02, 
   1.383577518672690e+02, -3.066479806614716e+01, 2.506628277459239e+00);
 *  var b = new Array(-5.447609879822406e+01, 1.615858368580409e+02,
    -1.556989798598866e
   +02, 6.680131188771972e+01, -1.328068155288572e+01 );
 *  var c = new Array(-7.784894002430293e-03, -3.223964580411365e-01,
    -2.400758277161838e
   +00, -2.549732539343734e+00, 4.374664141464968e+00, 2.938163982698783e+00);
 *  var d = new Array (7.784695709041462e-03, 3.224671290700398e-01,
    2.445134137142996e
   +00, 3.754408661907416e+00);
 *  // Define break-points.
    var plow = 0.02425; var phigh = 1 – plow;
 *  // Rational approximation for lower region:
    if ( p < plow ) { var q = Math.
   sqrt(-2*Math.log(p)); return (((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5])/((((
   d[0]*q+d[1])*q+d[2])*q+d[3])*q+1); }
 *  // Rational approximation for upper region:
    if ( phigh < p ) { var q = Math.
   sqrt(-2*Math.log(1-p)); return -(((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[
   5]) / ((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1); }
 *  // Rational approximation for central region:
    var q = p – 0.5; var r = q*q;
   return (((((a[0]*r+a[1])*r+a[2])*r+a[3])*r+a[4])*r+a[5])*q / (((((b[0]*r+b[1])*
   r+b[2])*r+b[3])*r+b[4])*r+1); }
 * Is there a way I can execute this?
 * I am fine to include the function within my theme functions.php file, if that
   helps.
 * Thank you so much for your help in advance!

Viewing 1 replies (of 1 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/execute-function-in-calculated-field/#post-10200608)
 * Hello [@mcyger](https://wordpress.org/support/users/mcyger/),
 * You simply should enter the function into the content of a “HTML Content” field,
   with a pair of script tags, as follows:
 *     ```
       <script>
       window['NORMSINV'] = function(p){
       /* The code HERE */
       };
       </script>
       ```
   
 * Please, include the function code without inline comments: // …..
 * And then, you can call this function from the equations:
 *     ```
       NORMSINV(fieldname1/1000000)
       ```
   
 * and that’s all.
    Best regards.

Viewing 1 replies (of 1 total)

The topic ‘Execute Function in Calculated Field’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [7 years, 11 months ago](https://wordpress.org/support/topic/execute-function-in-calculated-field/#post-10200608)
 * Status: resolved