---
title: any_value
description: |
  Returns any non-null value from the specified expression within a group.
  If no expression is provided, it defaults to the `$d` object.

  Returns `null` if all values in the group are `null`.
url: https://coralogix.com/docs/dataprime/language-reference/functions-reference/aggregation/any_value/
product: dataengine
feature: DataPrime Language
feature_id: dataprime-language
feature_identifier: dataengine/dataprime-language
last_updated: '2026-10-21'
---

# `any_value`

## Description

Returns any non-null value from the specified expression within a group. If no expression is provided, it defaults to the `$d` object.

Returns `null` if all values in the group are `null`.

## Syntax

```
any_value(expression: T?): T
```

## Arguments

| Name         | Type | Required  | Description                               |
| ------------ | ---- | --------- | ----------------------------------------- |
| `expression` | `T`  | **false** | Expression to evaluate. Defaults to `$d`. |

## Example

**Use case: Select any non-null username from a group of documents**

Suppose you want to group documents by team and retrieve any available username.

### Example data

```
{

    "userId": 1,

    "team": "A Team",

    "username": null

},

{

    "userId": 2,

    "team": "A Team",

    "username": "Ryan"

},

{

    "userId": 3,

    "team": "A Team",

    "username": "Anastasia"

}
```

### Example query

```
groupby team aggregate any_value(username) as random_username
```

### Example output

The output may vary depending on the order in which documents are processed:

```
{

"team": "A Team",

"random_username": "Ryan"

}
```
