Skip to main content

MEDIAN

Returns the median, or the number in the middle of the set of given numbers.

Syntax​

expression.MEDIAN(args);

expression - A variable that represents an ApiWorksheetFunction class.

Parameters​

NameRequired/OptionalData typeDefaultDescription
argsRequirednumber | number[] | ApiRange | ApiNameUp to 255 numeric values for which the median will be calculated. The first argument is required, subsequent arguments are optional. Arguments can be numbers, names, ranges, or arrays of numbers.

Returns​

number

Example​

Find the middle value from a set of numbers in a spreadsheet.

// What is the median number in a list in a spreadsheet?

// Extract the median value from a range of values in a spreadsheet.

const worksheet = Api.GetActiveSheet();
let func = Api.WorksheetFunction;
let median = func.MEDIAN(4,45,12,34,3,54,2,2);
worksheet.GetRange("C1").SetValue(median);