TREND

function TREND(
  arg1: ApiRange | number[] = null,
  arg2: ApiRange | number[] = null,
  arg3: ApiRange | number[] = null,
  arg4: boolean = null,
): number

Description

Returns numbers in a linear trend matching known data points, using the least squares method.

Parameters

arg1ApiRange | number[]default: null

A range or array of y-values from the y = mx + b equation.

arg2ApiRange | number[]default: null

An optional range or array of x-values from the y = mx + b equation, an array of the same size as an array of y-values.

arg3ApiRange | number[]default: null

A range or array of new x-values for which this function will return corresponding y-values.

arg4booleandefault: null

A logical value: the constant b is calculated normally if this parameter is set to true or omitted, and b is set equal to 0 if the parameter is false.

Returns

number

Try It

var oWorksheet = Api.GetActiveSheet();
var oFunction = Api.GetWorksheetFunction();
var month = ["Month", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var sales = ["Sales", "$1,500.00", "$1,230.00", "$1,700.00", "$1,000.00", "$980.00", "$1,470.00", "$1,560.00", "$1,640.00", "$1,420.00", "$1,100.00"];

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

oWorksheet.GetRange("C1").SetValue("Trend");
var oRange1 = oWorksheet.GetRange("B2:B11");
var oRange2 = oWorksheet.GetRange("A2:A11");
oWorksheet.GetRange("C2:C11").SetValue(oFunction.TREND(oRange1, oRange2));

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).