# Custom Fields

Custom fields allow admins and contributors to expand the data model by creating fields from existing source columns.

Creating custom fields can provide flexibility and adaptability for specific business calculations. Custom fields allow for new fields to be created to expand on the data fields provided.

<details>

<summary>Example: Custom fields are great for calculations. See below for a simple calculation.</summary>

<pre><code><strong>[custom_field] sales_amount = units_sold * price_per_unit
</strong></code></pre>

</details>

## When to Use Custom Fields?

Use custom fields when you need to add a field that does not exist in the source schema, but would be beneficial to have in the semantic layer to streamline insight generation.

{% hint style="warning" %}

#### Key Points To Note

* Use the SQL dialect that matches your connected data source when defining logic in the "Custom Calculation" box.
* In the calculation, only use the source name of the field from the db.table.
* Custom fields requiring joins to another table cannot be created.
  {% endhint %}

## Create a Custom Field

Let's walkthrough an example of how to use custom fields to convert the format of a "YYYY-MM-DD" date field into a fiscal-year-week field.

```
actual_payment_date  --> fiscal_year_week
   '2024-02-01'      -->  '2024-05'

```

### Identify the Source Name of the Field <a href="#id-1-the-more-clear-and-concise-you-are-the-better" id="id-1-the-more-clear-and-concise-you-are-the-better"></a>

Use the source name for each of the fields involved in the custom calculation.

{% hint style="warning" %}
Note: it is only possible to use the source name of the field in the db.table in the actual calculation
{% endhint %}

<figure><img src="/files/leKhx3b1IEi9elBbhyTj" alt=""><figcaption></figcaption></figure>

### Add a Custom Field <a href="#id-1-the-more-clear-and-concise-you-are-the-better" id="id-1-the-more-clear-and-concise-you-are-the-better"></a>

To add a custom field, edit the knowledge base and add a field.

<figure><img src="/files/6A8aMwwTOjUYwfkYbfEB" alt=""><figcaption></figcaption></figure>

### Select Custom Field <a href="#id-1-the-more-clear-and-concise-you-are-the-better" id="id-1-the-more-clear-and-concise-you-are-the-better"></a>

Select the custom field to open the creation menu.

<figure><img src="/files/JDzUmW52QUho42VtVrzS" alt=""><figcaption></figcaption></figure>

### Input SQL Calculation into Custom Calculation Field <a href="#id-1-the-more-clear-and-concise-you-are-the-better" id="id-1-the-more-clear-and-concise-you-are-the-better"></a>

Use the source name for each of the fields involved in the custom calculation. Make sure to use the correct SQL dialect that matches the data source you connected.

`to_char(actual_payment_date, 'IYYY-IW')`

<figure><img src="/files/7Sol3zZjNP5Ils97Mun6" alt=""><figcaption></figcaption></figure>

Add a semantic name and context for the field and press done.

### Validate Custom Calculation Field <a href="#id-1-the-more-clear-and-concise-you-are-the-better" id="id-1-the-more-clear-and-concise-you-are-the-better"></a>

The custom field is now available to be used in generating insights.

<figure><img src="/files/RxtAtdtbZbJNhhiHeQ1z" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lumi-ai.com/product-features/knowledge-base/tables/custom-fields.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
