Average-If function needed..
I am currently using a wonderful custom function called TypeSumField. I found it here. In short, it makes it possible to sum a certain field from records that meet a certain condition. (i.e. if category = "Bread and pastries" then Sum( amount ) )
The source code for this function is:
//This function will sum all SumFields whose TypeField = Type
//Start should =0 or blank
End = Count(TypeField);
counter = Start +1;
total = If(GetNthRecord(TypeField;counter)=Type; GetNthRecord(SumField;counter) ; 0 )
Case(counter<End ; total + TypeSumField(TypeField;Type;SumField;counter) ; total
What I need now is a comparable function, but then with average. So, that it calculates the average of the field "amount" of all records where the field "category" has the value "Bread and pastries".
Is it possible to do this with a custom function that is comparable to the TypeSumField custom function?