Skip to main content

RANK

Returns the rank of a number in a list of numbers: its size relative to other values in the list.

Syntax​

expression.RANK(arg1, arg2, arg3);

expression - A variable that represents a ApiWorksheetFunction class.

Parameters​

NameRequired/OptionalData typeDefaultDescription
arg1RequiredApiRange | ApiName | numberThe number for which the rank will be returned.
arg2RequiredApiRange | ApiName | number[]An array or range of numbers. Nonnumeric values are ignored.
arg3OptionalApiRange | ApiName | booleanThe numeric value that specifyes how to order the numbers. If it is 0 or omitted, the rank in the list will be sorted in descending order. Any other numeric value means that the rank in the list will be sorted in ascending order.

Returns​

number

Example​

Determine the position of a value within a sorted list of numbers in a spreadsheet.

// How do I find where a number ranks compared to others in a spreadsheet?

// Calculate the numeric standing of an item among a set of values in a spreadsheet.

const worksheet = Api.GetActiveSheet();

let valueArr = [7,6,5,5];

// Place the numbers in cells
for (let i = 0; i < valueArr.length; i++) {
worksheet.GetRange("A" + (i + 1)).SetValue(valueArr[i]);
}

//method params
let number = worksheet.GetRange("A3");
let range = worksheet.GetRange("A1:A4");
let order = 0;

let func = Api.WorksheetFunction;
let ans = func.RANK(number,range,order);

worksheet.GetRange("C1").SetValue(ans);