DAVERAGE
Averages the values in a field (column) of records in a list or database that match conditions you specify.
Syntax
expression.DAVERAGE(arg1, arg2, arg3);
expression
- A variable that represents a ApiWorksheetFunction class.
Parameters
Name | Required/Optional | Data type | Default | Description |
---|---|---|---|---|
arg1 | Required | ApiRange | ApiName | The range of cells that makes up the list or database. A database is a list of related data. | |
arg2 | Required | ApiRange | ApiName | number | string | The column which is used in the function. Either the label of the column in double quotation marks or a number that represents the column's position in the list. | |
arg3 | Required | ApiRange | ApiName | The range of cells that contains the conditions you specify. The range includes at least one column label and at least one cell below the column label for a condition. |
Returns
number
Example
- Code
- Result
let worksheet = Api.GetActiveSheet();
let func = Api.GetWorksheetFunction();
worksheet.GetRange("A1").SetValue("Name");
worksheet.GetRange("B1").SetValue("Age");
worksheet.GetRange("C1").SetValue("Sales");
worksheet.GetRange("A2").SetValue("Alice");
worksheet.GetRange("B2").SetValue(20);
worksheet.GetRange("C2").SetValue(200);
worksheet.GetRange("A3").SetValue("Andrew");
worksheet.GetRange("B3").SetValue(21);
worksheet.GetRange("C3").SetValue(300);
worksheet.GetRange("E1").SetValue("Sales");
worksheet.GetRange("E2").SetValue(">200");
let range1 = worksheet.GetRange("A1:C3");
let range2 = worksheet.GetRange("E1:E2");
worksheet.GetRange("E4").SetValue(func.DAVERAGE(range1, "Sales", range2));