Jump to content
  • 0

[Custom Function: ArrayStats]


Joris Aarts

Question

Posted

Laat toe om sum, count, max, ... te berekenen voor een variabele met meerdere repetitions. Je kan elke built-in FileMaker aggregate function gebruiken.

 

Syntax:

ArrayStats(Sum|Count|Average|... , $variabele, aantalRepetitions, temp)

 

Voorbeeld:

Variabele $Array met 3 repetitions:

$Array[1] = 7

$Array[2] = 6

$Array[3] = 10

 

ArrayStats("Sum"; "$Array"; 3; "") = 23

ArrayStats("Average"; "$Array"; 3; "") = 7,66666666667

ArrayStats("Sum"; "$Array"; 2; "") = 13

 

Voorbeeldbestand in bijlage

ArrayStats.zip

Array.JPG.4e6cefc89cd203c20dc946c6a4c83938.JPG

1 answer to this question

Recommended Posts

  • 0
Posted

Volledige functie als tekst (argumenten in eerste lijn):

 

//Arguments: statFunction; varName; numRepetitions; temp
//Calculates chosen stat for specified variable varName with number of repetitions in numRepetitions
//Example: ArrayStats("Sum" ; "$TestVar";3) where $TestVar contains values 1,2,3 in three repetitions, returns 6
//statFunction can contain one of FileMakers Aggregate functions: Sum, Count, Min, Max, Average, ...

Let([
       nextRepetition = numRepetitions - 1;
       varWithRepetition = varName & "[" & numRepetitions & "]";             //expand variable to specific repetition
       newTemp = temp  & ";" & varWithRepetition;                                    //add result to chain of repetitions 
       stripTemp = Middle(temp;Position(temp;";";1;1)+1;Length(temp));  //Remove everything before first ";" from chain for result
       resultString = statFunction & "(" &  stripTemp  & ")";                          //set up final calculation string with all repetitions
       result = Evaluate(resultString)                                                            //Now calculate it !
];
If(
    numRepetitions > 0;
    ArrayStats(statFunction; varName ; nextRepetition ; newTemp);
    result
   )
)

 

Veel groeten,

 

Joris Aarts

www.selene.be

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...