weighted_avg()

Aggregate. Calculates an arithmetically (or linearly) weighted average.

Syntax

weighted_avg ( expression )

Parameters

expression

A numeric expression that accepts integer, long, float, money, timestamp, and interval datatypes.

Usage

An arithmetically weighted average has multiplying factors that give different weights to different data points. In Event Processing, a weighted moving average (WMA) has the specific default meaning of weights which decrease arithmetically with the age of an event. So the oldest event is given the least weight and the newest event is given the most weight. The weighted average is expressed using the following formula:

Where
  • WMA – The weighted moving averagen - number of events in the group.
  • pM – Refers to the newest event.
  • pM-1 – Refers to the second newest event.
  • pM-n+1 – Refers to the oldest event.

The weighted average function could be used in circumstances that each value does to contribute equally to the group of values.