Skip to main content

Celonis Product Documentation

FIRST
Description

Returns the first element of the specified source column for each element in a group.

FIRST can be applied to any data type. The data type of the result is the same as the input column data type.

Syntax
 FIRST ( table.input_column [, ORDER BY table.column [ASC|DESC] ] )
  • table.input_column: The column which should be aggregated.

  • ORDER BY (optional): Elements of the specified column are used to determine the first element. ASC or DESC can be specified to use ascending or descending ordering. If the order direction is not specified, the ascending (ASC) order is used. Using FIRST with descending order is equivalent to using LAST with ascending order.

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]

This example computes the first element of a column.

Query

Column1

         FIRST ( "Table"."Value" )
        

Input

Output

Table

Value : int

1

2

3

Result

Column1 : int

1

[2]

This example computes the first value grouped by country.

Query

Column1

         "Table"."Country"
        

Column2

         FIRST ( "Table"."Value" )
        

Input

Output

Table

Country : string

Value : int

'US'

3

'DE'

10

'DE'

5

'FR'

5

'US'

4

'US'

1

Result

Column1 : string

Column2 : int

'DE'

10

'FR'

5

'US'

3

[3]

This example demonstrates the use of the optional ORDER BY clause.

Query

Column1

         "caseTable"."companyCode"
        

Column2

         FIRST ( "caseTable"."caseId" , ORDER BY "caseTable"."value" )
        

Input

Output

caseTable

caseId : int

companyCode : string

value : int

1

'001'

600

2

'001'

400

3

'001'

200

4

'002'

100

5

'002'

500

6

'003'

200

Result

Column1 : string

Column2 : int

'001'

3

'002'

4

'003'

6

[4]

This example computes the first element in a group with null values.

Query

Column1

         "Table"."Country"
        

Column2

         FIRST ( "Table"."Value" )
        

Input

Output

Table

Country : string

Value : int

'US'

null

'DE'

null

'DE'

null

'FR'

5

'US'

4

'US'

1

Result

Column1 : string

Column2 : int

'DE'

null

'FR'

5

'US'

4

See also: