help with finding the average of a field

38 views
Skip to first unread message

TC Freeman

unread,
Jul 30, 2022, 12:59:56 PM7/30/22
to mementodatabase
I need a script that finds the average of field B when field A contains a certain value.  If field B is null then I don't want to include it in the average.   I want to find different averages of field B for different possible values of field A.  Is this easy to do?

Er Mo

unread,
Jul 30, 2022, 1:27:31 PM7/30/22
to mementodatabase
Hallo
Man kann mit einem Skript die Bibliothek durchlaufen lassen und die Werte von Feld B nehmen wenn Feld A das zuläst . Was willst du mit den Ergebnis machen ?

Hi
You can script it through the library and take the values from field B if field A allows it. What do you want to do with the result?

Ernst

TC Freeman

unread,
Jul 30, 2022, 2:52:30 PM7/30/22
to mementodatabase
I'm thinking I would assign the result to a hidden integer field and then display that integer field using a JS field.
JS field would look something like this:

if (field("Field A") == 60) {
    var result = "Average is " + field("hiddenFieldB60Average");
} else if (field("Field A") == 61) {
    var result = "Average is " + field("hiddenFieldB61Average");
} else if (field("Field A") == 62) {
    var result = "Average is " + field("hiddenFieldB62Average");
} else if (field("Field A") == null) {
    var result = "Enter a value for Field A to get average";

result;

I think the script would need to trigger when creating or updating an entry and then update the appropriate hidden field for a specific Field A value.
Reply all
Reply to author
Forward
0 new messages