# `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

```dataprime
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:

```json
{
  "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

```dataprime
create temperature_description from
case_lessthan {
  $d.temperature_celsius,
  10 -> 'freezing',
  20 -> 'cold',
  30 -> 'fun',
  45 -> 'hot',
  _  -> 'burning'
}
```

### Example output

```json
{
  "temperature_celsius": 10,
  "temperature_description": "freezing"
},
{
  "temperature_celsius": 50,
  "temperature_description": "burning"
},
{
  "temperature_celsius": 20,
  "temperature_description": "cold"
}
```
