Table of Contents

Search

  1. Preface
  2. The Transformation Language
  3. Constants
  4. Operators
  5. Variables
  6. Dates
  7. Functions

Transformation Language Reference

Transformation Language Reference

MEDIAN

MEDIAN

Returns the median of all values in a selected port.
If there is an even number of values in the port, the median is the average of the middle two values when all values are placed ordinally on a number line. If there is an odd number of values in the port, the median is the middle number.
You can nest only one other aggregate function within MEDIAN, and the nested function must return a Numeric datatype.
The
Data Integration Service
reads all rows of data to perform the median calculation. The process of reading rows of data to perform the calculation may affect performance. Optionally, you can apply a filter to limit the rows you read to calculate the median.

Syntax

MEDIAN(
numeric_value
[,
filter_condition
] )
The following table describes the arguments for this command:
Argument
Required/
Optional
Description
numeric_value
Required
Numeric datatype. Passes the values for which you want to calculate a median. 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.
If the return value is Decimal with precision greater than 15, you can enable high precision to ensure decimal precision up to 38 digits.

Nulls

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

Group By

MEDIAN groups values based on group by ports you define in the transformation, returning one result for each group.
If there is no group by port, MEDIAN treats all rows as one group, returning one value.

Example

To calculate the median salary for all departments, you create an Aggregator transformation grouped by departments with a port specifying the following expression:
MEDIAN( SALARY )
The following expression returns the median value for orders of stabilizing vests:
MEDIAN( SALES, ITEM = 'Stabilizing Vest' )
ITEM
SALES
Flashlight
85
Stabilizing Vest
504
Stabilizing Vest
36
Safety Knife
5
Medium Titanium Knife
150
Tank
NULL
Stabilizing Vest
441
Chisel Point Knife
60
Stabilizing Vest
NULL
Stabilizing Vest
1044
Wrist Band Thermometer
110
RETURN VALUE:
472.5

0 COMMENTS

We’d like to hear from you!