# Discussions

View Only

## Median and Percentiles using Java script  #### _anom Diebolt)12-20-2013 12:40  • #### 1.  Median and Percentiles using Java script

Posted 12-19-2013 20:07
As median, percentiles are not allowed in quickbase, is it possible to write a java script to calculate them and call it using the formula url field. Here are the detailed steps would like to do

I have a details table with the data. Want to read the data from that table using java script
Calculate the necessary values
Populate in to other table with the calculated values
Trigger this java script using formula URL either by button or an event in the form

Please let me know how can i acheive this

• #### 2.  RE: Median and Percentiles using Java script

Posted 12-20-2013 12:40
I assume you are viewing a parent record when you want to initiate this process.

When you are on this form for the parent record, there is a global variable named kRid which represents the [Record ID#] of the record being displayed. So the conceptual inputs for this script are (1) kRid along with (2) the child dbid (cdbid) and (3) the field id (fid) of the single field in the child table you want to calculate statistics on.

Using this library for the statistics calculations:
http://www.javascriptstats.com
the code in the following entry will calculate all of you basic statistics such as mean, median, mode, min, max, range, sum, sumOfSquaresm, variance, standard deviation

Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=237

In a nutshell the code above waits till the statistics library has loaded and the child data has arrived and then calculates each of the above statistics using underscore and the stats library. Once the statistics are calculated you can splice the results into the form or perform an AJAX call to stuff the results into a table, user defined page or wherever you want it to go.

• #### 3.  RE: Median and Percentiles using Java script

Posted 01-16-2014 00:01
Thanks for the elaborate answer. I have only one table and i want to initiate the process separately when I click on a button or some thing else. Also, since its only 1 table and i want to calculate these stats based on some kind of grouping and filtering of data, how do i supply the separate groups to the javascript to calculate stats. Do i need to use some querying techniques here?

• #### 4.  RE: Median and Percentiles using Java script

Posted 07-03-2018 02:38
Hi Dan!

Such an old post but its worth a try, so I've done everything in the scripts but I want to pull the median into a new field.   Any advice on how to do that? I'm new to java as a whole.

I've named my code page "median.js" and created the javastats.js from a github that was able to grab the original before the java stats site went down.  All i need from the old stats script is to pull the median.