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.
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.
@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% ?
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);
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