May 05, 2020 08:12 AM
You may be in a situation where you have a dataset with a lot of numbers, and you can’t find any meaning in it. (It’s me. I’m in this situation :raising_hand_woman:t5: ) If I could only break those numbers up into smaller groups, maybe I’d be able to better digest and distill some meaning.
As a first start, I figured why not group these numbers into a nice set of four quartiles: Low, Below Median, Above Median, and High. That way I can use Airtable’s grouping to get a better sense of what I’m dealing with. I’ll preface by saying that I majored in English and I do not stand behind any mathematical concepts I’m using. If they’re wrong, call me out, I seriously don’t know better.
Until recently, the only way you could run calculations on the content of an entire field was through rollups, which was pretty inconvenient and took some mental gymnastics to understand. But, with the scripting block you can do this analysis pretty neatly. I found this nice script over on Stack Exchange and built around it so the script also accounts for 0 & empty values.
I realized that I didn’t want to group by three different fields (too much nesting), but I did want those three fields to inform my groups. Basically I wanted to tag each record based on a criteria:
:star2: All Star = 3/3 Groups are High or Above Median
:mushroom: Positive Signal = 2/3 Groups are High or Above Median
:rotating_light: Negative Signal = Everything Else
I started writing a complicated IF statement, that only I could decipher, so I thought, maybe a script will do this better. Which it totally did.
May 05, 2020 11:14 AM
May 05, 2020 11:44 AM
And yet, you are quite good at this. :winking_face: Your approach places you at the doorstep of machine-learning. You should step across.
May 05, 2020 12:17 PM
Updated! Thanks for the reminder.
May 05, 2020 12:18 PM
Ha! Thanks Bill, glad this is co-signed by you!
May 26, 2020 03:17 PM
English majors unite! English majors can code, just like anyone else. In fact, I often think of my code in terms of writing a composition. Functions are like paragraphs. Variables are vocabulary. Methods are verbs. Properties are adjectives. Syntax is grammar. Debugging is proofreading.
Mar 22, 2021 07:44 AM
@VictoriaPlummer Well, I’ve to say this script 's what I’m looking for. This’s called RFM method to calculate for ranking point.
In your case, You script Volume range from volume field Q1(Quartile 1 (25%) ,Q2 (Quartile 2 (50%) ,Q3 (Quartile 3 (75%). What would I change something to display this values of 25% ?
Mar 25, 2021 09:35 AM
So glad this helped! The below section in the script is where i think you can change the values for the quartiles. You can even remove some if you’d like.
const q25 = arr => quantile(arr, .25); const q50 = arr => quantile(arr, .50); const q75 = arr => quantile(arr, .75); const max = arr => quantile(arr, 1);
Apr 16, 2021 02:42 AM
Still get error when edit, Can you help a bit script to display value of q25, q50, q75 ?
Jan 18, 2022 03:51 AM
Hi Victoria, congratulations on pulling all this together and thanks for sharing.
In the description you say this accounts for empty values, however I am running into an error if I delete any of the values in the “Volume”, “Price” or “Revenue” columns (as is the case in the data I am trying to apply this to).
Is there an easy fix without me having to manually add zeros to my data? (in my use case it would distort the data).
PS: This is the error I get
TypeError: Cannot convert undefined or null to object
at getBuckets on line 84
at on line 92
at main on line 90