Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fgeneral%2Ffirstnonnull.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fgeneral%2Ffirstnonnull.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `firstNonNull`

## Description

Return the first non-null value from a list of arguments, in the order they are provided.

Note

Works only on scalar values such as `number`, `string`, or `timestamp`. Does not work on objects.

## Syntax

Like many functions in DataPrime, `firstNonNull` supports<!-- --> [two notations](https://docs-docusaurus.kinsta.page/dataprime/language-reference/functions-reference/.md),<!-- --> **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

* Function notation
* Method notation

```
firstNonNull(value: any, ...values: any): any
```

```
(value: any).firstNonNull(...values: any): any
```

## Arguments

| Name        | Type  | Required | Description                                      |
| ----------- | ----- | -------- | ------------------------------------------------ |
| `value`     | `any` | **true** | The first argument to check for a non-null value |
| `...values` | `any` | **true** | Subsequent arguments to check, in order          |

## Example

**Use case: Consolidate inconsistent field names for the same logical value**

Logs may contain a user identifier under different field names (`userId`, `user_id`, `user_identifier`). Instead of writing complex conditionals, `firstNonNull` returns the first populated value across these fields, creating schema-on-read consistency.

### Example data

```
{

    "userId": "123",

    "user_id": null,

    "user_identifier": null

},

{

    "userId": null,

    "user_id": "456",

    "user_identifier": null

},

{

    "userId": null,

    "user_id": null,

    "user_identifier": "789"

}
```

### Example query

* Function notation
* Method notation

```
choose canonical_user_id from firstNonNull(userId, user_id, user_identifier)
```

```
choose canonical_user_id from userId.firstNonNull(user_id, user_identifier)
```

### Example output

```
{

    "canonical_user_id": "123"

},

{

    "canonical_user_id": "456"

},

{

    "canonical_user_id": "789"

}
```
