Average

Calculates the arithmetic mean of all numeric arguments.

Syntax

Average(value1, value2, ...)
Average(array)

Parameters

  • values (number…): One or more numeric values to average, OR
  • array (array): A single array of numeric values

Returns

  • number: The arithmetic mean of all provided numeric values, or null if no numeric arguments are provided

Description

Calculates the arithmetic mean (average) by summing all numeric arguments and dividing by the count. Non-numeric arguments are ignored. Returns null if no numeric arguments are provided.

Examples

Basic average

var avg = Average(10, 20, 30)  # Returns 20

Average with decimals

var avg = Average(1.5, 2.5, 3.0)  # Returns 2.333...

Single value

var avg = Average(42)  # Returns 42

Calculate grade average

var grades = [85, 92, 78, 95, 88]
var avg = Average(grades)
# Returns 87.6

With Sum for comparison

var numbers = [10, 20, 30, 40, 50]
var total = Sum(numbers[0], numbers[1], numbers[2], numbers[3], numbers[4])
var count = Length(numbers)
var manualAvg = total / count  # 30

var funcAvg = Average(numbers[0], numbers[1], numbers[2], numbers[3], numbers[4])
# Both equal 30

Notes

  • Returns null if no numeric arguments are provided
  • Non-numeric arguments are silently ignored
  • Accepts a single array argument for convenience
  • For calculating median (middle value), use Median
  • For calculating mode (most frequent), use Mode
  • Related: Sum, Min, Max

Back to top

Copyright © Mesch Systems. All rights reserved.