# Calculated columns

[Calculated columns](https://docs.syntho.ai/configure-a-data-generation-job/configure-column-settings/calculated-columns) allow you to define custom formulas to generate or transform data using logical, mathematical, statistical, or text-based operations. These formulas are applied after other generators like mockers or AI synthesis, ensuring that all base data is available before the calculation is performed.

#### When to use

* To clean or reformat data (e.g. trimming, date formatting)
* To apply conditional logic (e.g. gender-based name generation)
* To compute derived values from other columns (e.g. sales + tax)
* To categorize or flag data based on specific criteria

#### When not to use

* For straightforward mock data generation without dependencies
* When no conditional logic is needed
* If the column is already correctly populated or handled by simpler generators

***

#### Interactive guide: How to apply a calculated column formula

Follow the interactive guide below to apply a calculated column formula.

{% embed url="<https://www.guidejar.com/guides/f304989a-0496-4a02-8659-2762e0a157f8>" %}

#### [Syntax and structure](https://docs.syntho.ai/configure-a-data-generation-job/configure-column-settings/calculated-columns#syntax)

Calculated columns follow a structured expression syntax combining functions, column references, constants, and mockers.

#### Example formulas

**1) `ROUND` — round a number to&#x20;*****N*****&#x20;decimals**

```dax
ROUND(
  [AMOUNT],
  2
)
```

* `number`: the value to round. Example: `[AMOUNT]`.
* `count`: decimal places. Example: `2` rounds to cents.

**2) `IF` — conditional logic**

```dax
IF(
  [COUNTRY] = "US",
  "domestic",
  "international"
)
```

* `test`: a condition that returns `TRUE` or `FALSE`. Example: `[COUNTRY] = "US"`.
* `then value`: returned when `test` is `TRUE`. Example: `"domestic"`.
* `otherwisevalue`: returned when `test` is `FALSE`. Example: `"international"`.

**3) `DATEADD` — shift a date by a fixed interval**

```dax
DATEADD(
  [ORDER_DATE],
  14,
  "day"
)
```

* `dates`: a date or datetime column. Example: `[ORDER_DATE]`.
* `number_of_intervals`: how many units to move. Example: `14`.
* `interval`: `"year"`, `"quarter"`, `"month"`, or `"day"`.

**4) Invoice total (combined) — arithmetic + null handling + rounding**

```dax
ROUND(
  ([AMOUNT] * (1 + IFNULL([TAX_RATE], 0))) - IFNULL([DISCOUNT], 0),
  2
)
```

Uses `IFNULL(value, replacement_value)` to guard against missing inputs.

**5) Normalized email (combined) — text functions + mocker**

```dax
SUBSTITUTE(
  CONCATENATE(
    LOWER(TRIM([FIRSTNAME])),
    ".",
    LOWER(TRIM([LASTNAME])),
    "@",
    MOCK_FREE_EMAIL_DOMAIN
  ),
  " ",
  ""
)
```

Builds an email-like string, normalizes casing, and removes spaces.

***

#### Key syntax rules

* **Column reference:** `[ColumnName]` for same-table columns
* **Functions:** `IF()`, `AND()`, `DATE()`, etc.
* **Mockers:** Use `MOCK_FIRST_NAME`, or `MOCK_CONSISTENT_FIRST_NAME` for consistent mapping
* **Operators:** `+`, `-`, `*`, `/`, `=`, `<>`, `<`, `>`
* **Constants:** Use strings `"text"`, numbers `100`, or dates `DATE(2020, 12, 31)`
* **Avoid:** Column names starting with `_`, which will cause formula errors

***

#### Using mockers in formulas

To insert mock data dynamically within formulas:

* Type `MOCK_` and choose from the autosuggest list
* Use names like `MOCK_FIRST_NAME`, `MOCK_COMPANY_EMAIL`
* For consistent mapping, use `MOCK_CONSISTENT_FIRST_NAME`, etc.

***

## Supported data types

| Generator          | Supported data types                    |
| ------------------ | --------------------------------------- |
| Calculated Columns | Categorical, Discrete, Continuous, Date |

***

Calculated columns give you full control over how synthetic values are created or transformed. They’re ideal for applying custom logic while retaining flexibility in the data generation process.
