Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fcases%2Fcase_lessthan.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%2Fcases%2Fcase_lessthan.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `case_lessthan`

## Description

Returns a value based on whether a number is less than one of several thresholds.

This function is a shorthand for `case` expressions with `<` (less than) logic and helps shorten queries that would otherwise repeat conditional statements. If no clause matches and no `_` fallback is present, `case_lessthan` returns `null`.

Note

`case_lessthan` checks clauses top-to-bottom and returns the **first match**, so order matters.

## Syntax

```
case_lessthan {

n: number,

value1: number -> result1,

value2: number -> result2,

...

valueN: number -> resultN,

_              -> default

}
```

## Arguments

| Name     | Type     | Required  | Description                                           |
| -------- | -------- | --------- | ----------------------------------------------------- |
| `n`      | `number` | **true**  | The numeric expression to compare                     |
| `value`  | `number` | **true**  | A threshold value for comparison                      |
| `result` | `any`    | **true**  | The value to return if `n` is less than the threshold |
| `_`      | `any`    | **false** | Default value if no thresholds match                  |

## Example

**Use case: Map temperature values to descriptions**

Suppose you want to create a field `temperature_description` that provides a readable label for temperatures in Celsius. Consider these log documents:

```
{

  "temperature_celsius": 10

},

{

  "temperature_celsius": 50

},

{

  "temperature_celsius": 20

}
```

The comparison thresholds should be listed in ascending order, since the first match is returned. For example, a value of `20` is less than both `45` and `30`, but the correct match is `30 -> 'fun'` because it appears first in ascending order.

### Example query

```
create temperature_description from

case_lessthan {

  $d.temperature_celsius,

  10 -> 'freezing',

  20 -> 'cold',

  30 -> 'fun',

  45 -> 'hot',

  _  -> 'burning'

}
```

### Example output

```
{

  "temperature_celsius": 10,

  "temperature_description": "freezing"

},

{

  "temperature_celsius": 50,

  "temperature_description": "burning"

},

{

  "temperature_celsius": 20,

  "temperature_description": "cold"

}
```
