Table of Contents

Search

  1. Preface
  2. Function reference
  3. Constants
  4. Operators
  5. Dates
  6. Functions
  7. System variables
  8. Datatype reference

Function Reference

Function Reference

AVG

AVG

Returns the average of all values in a group of rows. Optionally, you can apply a filter to limit the rows you read to calculate the average.
You can nest only one other aggregate function within AVG, and the nested function must return a numeric data type.
You cannot nest aggregate functions in advanced mode.
Use only in
mapping
tasks.

Syntax

AVG(
numeric_value
[,
filter_condition
] )
Argument
Required/
Optional
Description
numeric_value
Required
Numeric data type. Passes the values for which you want to calculate an average. You can enter any valid transformation expression.
filter_condition
Optional
Limits the rows in the search. The filter condition must be a numeric value or evaluate to TRUE, FALSE, or NULL. You can enter any valid transformation expression.

Return Value

Numeric value.
NULL if all values passed to the function are NULL or if no rows are selected. For example, the filter condition evaluates to FALSE or NULL for all rows.

Nulls

If a value is NULL, AVG ignores the row. However, if all values passed are NULL, AVG returns NULL.

Group By

AVG groups values based on group by fields you define in the transformation, returning one result for each group.
If there is not a group by field, AVG treats all rows as one group, returning one value.

Example

The following expression returns the average wholesale cost of flashlights:
AVG( WHOLESALE_COST, ITEM_NAME='Flashlight' )
ITEM_NAME
WHOLESALE_COST
Flashlight
35.00
Navigation Compass
8.05
Regulator System
150.00
Flashlight
29.00
Depth/Pressure Gauge
88.00
Flashlight
31.00
RETURN VALUE:
31.66

Tip

You can perform arithmetic on the values passed to AVG before the function calculates the average. For example:
AVG( QTY * PRICE - DISCOUNT )

0 COMMENTS

We’d like to hear from you!