# 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. &#x20;

<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.&#x20;
* In the calculation, only use the source name of the field from the db.table.&#x20;
* 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.&#x20;

```
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.&#x20;

{% 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="https://1092914297-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbsNNtXffkOLYrtYRQIcx%2Fuploads%2FNcGuQJ8sT7LVaCu61DM0%2FUntitled%20presentation%20(14).jpg?alt=media&#x26;token=dfbd09fa-aa5a-4340-a227-ad6778c4ff33" 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.&#x20;

<figure><img src="https://1092914297-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbsNNtXffkOLYrtYRQIcx%2Fuploads%2FA2esmelWFHEWo1b9rSGp%2FUntitled%20presentation%20(15).jpg?alt=media&#x26;token=6674c2ca-0518-4971-988a-57779f9bcee3" alt=""><figcaption></figcaption></figure>

### &#x20;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="https://1092914297-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbsNNtXffkOLYrtYRQIcx%2Fuploads%2F9khpvhwt5wgvWSAIHNZJ%2FUntitled%20presentation%20(16).jpg?alt=media&#x26;token=b107f006-926e-459f-9ab7-8a6a7d1fcb6e" 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="https://1092914297-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbsNNtXffkOLYrtYRQIcx%2Fuploads%2Fohjx8sAe7dnqKWoTYO4e%2FUntitled%20presentation%20(17).jpg?alt=media&#x26;token=f1e537d9-e566-425b-bcf6-d84639d59c61" 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="https://1092914297-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbsNNtXffkOLYrtYRQIcx%2Fuploads%2FDY4RmAFTuWJkQG1dtp4N%2FUntitled%20presentation%20(18).jpg?alt=media&#x26;token=91445f56-11f3-4152-8f68-e39c512ee6df" alt=""><figcaption></figcaption></figure>
