{{sidenavigation.sidenavigationExpandLabel}}
{{getMsg('Help_YouAreHere')}}: {{page.title}} {{page.title}}
{{$root.getMsg("downLoadHelpAsPdf")}} {{helpModel.downloadHelpPdfDataStatus}}

WeightedAverage

Computes the average value of a field or array weighted by a second field or array.
You can also give a condition how to group the records.

The weighted average is calculated by multiplying each x value with its corresponding y value, adding up these values, and dividing by the sum of all y values:

(x1*y1+x2*y2+...+xn*yn) / (y1+y2+y3+...+yn)

Usage:

WeightedAverage( fld1, fld2 )
WeightedAverage( fld1, fld2, condFld )
WeightedAverage( fld1, fld2, condFld, cond )

Parameters:

fld1 The name of a field or array variable whose values should be used to calculate the average value.
fld2 The "weights" to average the corresponding values of fld1 with. If each value of fld2 was 1, the result would be the same as normal averaging.
condFld The name of the field that groups the values of fld1 (if fld1 isn't an array).
cond A string declaring the type of grouping to be used on condFld. This only makes sense for groups based on Date, DateTime, Time, and Boolean fields. See Summary Field Conditions for a list of strings you can use here.

Returns:

A fractional number.

Examples:

// computes the weighted average of the values of a field "production" of table "factory"
WeightedAverage({factory.production},{factory.production_weighting})
// computes the average of the array elements
WeightedAverage([1,2,3,4,5,6],[0.6,1,0.4,-0.1,2,1])	//returns 3.96
// computes the average of the values of the formula makeArray weighted by the values
// of the formula makeWeightes
WeightedAverage({@makeArray},{@makeWeights})
// computes the average of the sales amount of all vendors weighted by its ratings and
// grouped by vendor
WeightedAverage({Sales.Sale_Amount},{Vendors.Rating},{Vendors.VendorID})

Notes:

If the values in fld1 should be grouped, a group based on condFld is needed. If the group does not exist in the report, you can add it using i-net Designer or using API method: Engine.addGroup.

See also:

i-net Clear Reports
This application uses cookies to allow login. By continuing to use this application, you agree to the use of cookies.


Help - WeightedAverage