Skip to main content

Celonis Product Documentation

MEDIAN
Description

This function calculates the median per group. Median can be applied to INT, FLOAT or DATE columns.

The median is the middle element of a group. If the group has an even number of elements, the higher value of the two middle values is taken as the median for INT and FLOAT data types. For DATE values, it takes the more recent date.

Syntax
 MEDIAN ( table.column )
NULL handling

NULL values are ignored, so they do not influence the result. If all the values of a group are NULL, the result for this group is also NULL.

Examples

[1]

Median of column with 3 rows.

Query

Column1

         MEDIAN ( "Table"."Column" )
        

Input

Output

Table

Column : int

1

2

3

Result

Column1 : int

2

[2]

Median of column with 4 rows. If a group has an even number of entries, the upper value of the two middle values is taken.

Query

Column1

         MEDIAN ( "Table"."Column" )
        

Input

Output

Table

Column : int

1

2

3

4

Result

Column1 : int

3

[3]

Get the median value by country.

Query

Column1

         "Table"."Country"
        

Column2

         MEDIAN ( "Table"."Values" )
        

Input

Output

Table

Country : string

Values : int

'US'

3

'DE'

10

'DE'

5

'FR'

5

'US'

4

'US'

3

Result

Column1 : string

Column2 : int

'DE'

10

'FR'

5

'US'

3

[4]

Get the median value mixed with nulls, grouped by country.

Query

Column1

         "Table"."Country"
        

Column2

         MEDIAN ( "Table"."Values" )
        

Input

Output

Table

Country : string

Values : int

'FR'

10

'FR'

null

'DE'

null

Result

Column1 : string

Column2 : int

'DE'

null

'FR'

10

See also: