# Create Formulaic CDT Fields

## Overview

Mathematical expressions and formulas can be utilized within Custom Data Type Fields (CDTFs) to automatically calculate values or combine data from multiple fields. Formulaic fields can derive answers from two or more fields, perform mathematical calculations, or concatenate string values into a single result. These fields are useful for computing derived metrics, combining patient information, or calculating scores based on assessment answers.

Formulaic CDTFs can be associated with multiple Data Views, Assessments, Charts and Graphs throughout your Welkin environment.

## Prerequisites

Before creating a formulaic custom data type field:

1. Create a Custom Data Type (CDT) in Designer. For detailed instructions, see the [Custom Data Types (CDT): Designer](/designer/custom-data-types/custom-data-types-cdt-designer.md) guide.
2. Ensure you have the necessary data fields already created within the CDT that will be referenced in the formula.

## Creating a Formulaic Field

### Step 1: Set Up the Base CDT

1. Log into Designer
2. Navigate to **Custom Data** > **Data Types**
3. Create or open an existing CDT
4. Click **+ Data Field** to add a new field to your CDT

### Step 2: Configure the Field Type

When creating a formulaic field, set the field configuration as follows:

1. Enter a **Name** for the field (lowercase, numbers, underscores, or hyphens)
2. Set the **Type** to one of the following:
   * **Formula** – for mathematical calculations
   * **Integer** or **Float** – for numeric results
   * **Text** – for string concatenation results

### Step 3: Create List Options with Numeric Values

If using a List field type that will feed into formulas:

1. Set **Type** to "List"
2. Set **Value Type** to "Integer" or "Float" to assign numeric values to each option
3. In the **Options field**, add your answer choices and their corresponding point values

**Example:**

* Question: "Did the patient meet their goal?"
* Options:
  * Yes = 2 points
  * No = 1 point
  * Not assessed = 0 points

### Step 4: Define the Formula Expression

1. Select **Type** = "Formula"
2. In the formula editor, you can:
   * **Reference fields** from the same CDT using field variable syntax
   * **Perform calculations** using operators (+, -, \*, /, etc.)
   * **Combine strings** by referencing text fields

**Formula Examples:**

* **BMI Calculation:** `(weight_field / (height_field * height_field)) * 703`
* **Age Calculation:** Calculate years between two dates
* **Score Combination:** `field1_value + field2_value + field3_value`
* **String Concatenation:** `first_name_field + " " + last_name_field`

### Step 5: Publish the Configuration

1. Click **Save** to save your changes
2. Click **Publish** to make the formulaic field available in Care and other visual components
3. The formula will automatically calculate values whenever the referenced fields are updated

## Using Formulaic Fields in Assessments and Data Views

Once your formulaic CDTF is created and published, you can:

* **Add to Assessments** – Include the formulaic field in assessment forms to display calculated results
* **Display in Charts & Graphs** – Visualize calculated data over time in line graphs, bar graphs, or pie charts
* **Reference in Automations** – Trigger automations based on calculated values
* **Show in Patient Data Views** – Display derived metrics in the Care portal patient profile

## Best Practices

* **Test formulas thoroughly** before publishing to ensure accuracy
* **Document formula logic** in your naming conventions for team clarity
* **Use Integer or Float types** for numeric calculations to ensure proper math operations
* **Reference only fields** that will consistently have values to avoid null calculation errors
* **Keep formulas simple** when possible for better performance and easier maintenance
* **Consider decimal precision** when setting Float field types for currency or percentages

## Limitations and Considerations

* Formulas are recalculated automatically when source fields are updated
* Circular references (where Field A depends on Field B, and Field B depends on Field A) are not supported
* Formulas execute synchronously; very complex calculations may impact performance
* Formula fields cannot reference fields from different CDTs (cross-CDT references are not supported)

## Related Topics

* [Custom Data Types (CDT): Designer](/designer/custom-data-types/custom-data-types-cdt-designer.md) – Creating and managing CDTs
* [Custom Field Types](/designer/custom-data-types/custom-field-types.md) – Reusable field type templates
* [Charts & Graphs: How to Configure](/designer/charts-and-graphs/charts-graphs-how-to-configure.md) – Displaying calculated data visually
* [How to Add Conditionality to Assessments](/designer/documents-and-assessments/how-to-add-conditionality-to-assessments.md) – Conditional logic in forms
* [Designer: Feature Overview – Custom Data Types](/designer/custom-data-types/custom-data-types.md) – General CDT overview


---

# 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.welkinhealth.com/designer/custom-data-types/create-formulaic-custom-data-type-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.
