> For the complete documentation index, see [llms.txt](https://docs.telm.ai/telmai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.telm.ai/telmai/profiling-data/compound-attributes.md).

# Custom Attributes

Build a new attribute from an SQL-like expression over other attributes, then profile and monitor it like any other.

A **custom attribute** is calculated from other attributes of the same asset with an SQL-like expression. Once created, it is profiled and can be monitored like any other attribute. Custom attributes were previously called compound attributes.

For example, you can combine `first_name` and `last_name` into one value, or flag orders that took more than 10 days to ship.

## Add a custom attribute

1. Open the asset from **Assets** and go to its **Attributes** tab.
2. Click **Add custom attribute**.
3. In **New custom attribute**, fill in:
   * **Attribute ID** — the name of the new attribute. Telmai suggests one; you can change it.
   * **Attributes to build from** — the attributes the expression uses, from 1 to 10.
   * **Expression** — the SQL-like expression that calculates the value, up to 250 characters. See [List of Supported Functions](https://docs.telm.ai/telmai/profiling-data/compound-attributes/list-of-supported-functions.md) and the examples below.
4. Check the expression: Telmai validates it as you type. Enter values for the attributes it uses, or pick from samples taken from the actual data, to see the result.
5. Click **Create**.

The new attribute appears in the **Attributes** tab, under the **Custom** filter. Its values are calculated on the next scan. To alert on it, add a monitor on the custom attribute from the asset's **Monitors** tab. See [Creating a Monitor](https://docs.telm.ai/telmai/monitoring-data/monitors-management/creating-a-monitor.md).

## Writing expressions

* The expression is checked to make sure it is valid SQL as you type.
* Some expressions pass validation but fail when the scan runs, because of type casting. Cast values to the type each function expects.
* **The result must be a string.** If the expression returns another type, such as a boolean, cast it to a string. For example, `contains(last_name, 'Smith')` returns a boolean, so write `cast(contains(last_name, 'Smith') as string)`.
* **Attribute values arrive as strings.** Cast them to the type a function needs. For example, `date_add` takes a date and a number, so write `date_add('2016-07-30', cast(my_number as int))`.

## Examples

**Example 1:** flag long names.

```sql
LENGTH(CONCAT_WS(",", firstname, lastname)) > 100
```

The result is a boolean, so cast it to a string:

```sql
CAST(LENGTH(CONCAT_WS(",", firstname, lastname)) > 100 AS STRING)
```

**Example 2:** flag orders older than 10 days.

```sql
IF(DATEDIFF(current_timestamp(), orderdate) > 10, true, false)
```

Return string values instead of booleans:

```sql
IF(DATEDIFF(current_timestamp(), orderdate) > 10, 'true', 'false')
```

**Example 3:** check that an order has a location and a valid price.

```sql
IF(ISNOTNULL(country) AND ISNOTNULL(city) AND (price <= 100), 'true', 'false')
```

`price` arrives as a string, so cast it to a number first:

```sql
IF(ISNOTNULL(country) AND ISNOTNULL(city) AND (CAST(price AS DOUBLE) <= 100), 'true', 'false')
```
