# EVAL

The `EVAL` command allows you to add new columns with calculated values to your dataset.

## Syntax

`EVAL [column1 =] value1[, ..., [columnN =] valueN]`

### Parameters

#### `columnX`

- The name of the column to be added or updated.
- If a column with the same name already exists, it will be replaced by the new column.
- If a column name is used multiple times, only the rightmost definition is applied.

#### `valueX`

- The value to assign to the column. This can be a literal, an expression, or a function.
- You can reference columns defined earlier in the same `EVAL` command.

## Notes

EVAL supports the following types of functions:
- Mathematical functions
- String functions
- Date-time functions
- Type conversation functions
- Conditional functions and expressions
- Multi-value functions

Aggregation functions are NOT supported for EVAL.

## Examples

### Adding new calculated columns

Add two new columns, `height_feet` and `height_cm`, by performing calculations on the `height` column:

```esql
FROM employees
| SORT emp_no
| KEEP first_name, last_name, height
| EVAL height_feet = height * 3.281, height_cm = height * 100
```

### Overwriting an existing column

Replace the `height` column with a new value calculated by converting it to feet:

```esql
FROM employees
| SORT emp_no
| KEEP first_name, last_name, height
| EVAL height = height * 3.281
```

### Adding a column without specifying a name

If no column name is provided, the new column will be named after the expression itself. For example, this query adds a column named `height*3.281`:

```esql
FROM employees
| SORT emp_no
| KEEP first_name, last_name, height
| EVAL height * 3.281
```

### Using a column with special characters in subsequent commands

When a column name contains special characters, enclose it in backticks (`) to reference it in later commands:

```esql
FROM employees
| EVAL height * 3.281
| STATS avg_height_feet = AVG(`height * 3.281`)
```

Any number of evaluations can be performed in a single EVAL command

```esql
FROM triangle
| EVAL cos = COS(angle), tan = TAN(angle), sin = SIN(angle), acos=ACOS(angle), asin=ASIN(angle)
| SORT angle DESC
| LIMIT 10
```

### Limitations
- If a column with the same name already exists, the existing column is dropped.
- If a column name is used more than once, only the rightmost duplicate creates a column.
