AVERAGEIF

function AVERAGEIF(arg1: ApiRange = null, arg2: number | string = null, arg3: ApiRange = null): number

Description

Finds the average (arithmetic mean) for the cells specified by a given condition or criteria.

Parameters

arg1ApiRangedefault: null

The range of cells which will be evaluated.

arg2number | stringdefault: null

The condition or criteria in the form of a number, expression, or text that defines which cells will be used to find the average.

arg3ApiRangedefault: null

The actual cells to be used to find the average. If omitted, the cells in the range are used.

Returns

number

Try It

var oWorksheet = Api.GetActiveSheet();
var oFunction = Api.GetWorksheetFunction();
var numbers = [67, 87, 98, 45];

for (var i = 0; i < numbers.length; i++) {
   oWorksheet.GetRange("A" + (i + 1)).SetValue(numbers[i]);
}

var oRange = oWorksheet.GetRange("A1:A4");
oWorksheet.GetRange("C1").SetValue(oFunction.AVERAGEIF(oRange, ">45"));

Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).