Median and Percentiles using Java script

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • Answered
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
Photo of Prasad

Prasad

  • 0 Points

Posted 6 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,434 Points 20k badge 2x thumb
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.
Photo of Prasad

Prasad

  • 0 Points
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?
Photo of Stephen

Stephen

  • 226 Points 100 badge 2x thumb
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.
(Edited)