# Calculated or related values

These generators calculate values based on a script, formula, or on other values in the database.

For details about each generator and how to configure them in the application, go to [calculated-or-related-values](https://docs.tonic.ai/fabricate/rule-based-tables-and-columns/table-columns/generator-reference/calculated-or-related-values "mention") in the generator reference.

## AI

Generates data values based on a prompt that you provide.

```json
{
  "name": string,
  "data_type": string,
  "generator": "AI",
  //  Generator-specific fields
  "ai_prompt": string, //AI prompt to use to populate the column
  // End generator-specific fields
  "group_key": string,
  "percent_null": integer,
  "virtual": boolean,
  // Advanced options
  "primary_key": boolean,
  "index": boolean,
  "seed": string,
  "postprocessing_sql": string
}
```

## Character Sequence

Populates a column with a value that uses a specific pattern. The pattern can include both random characters of a specific type and specific characters.

```json
{
  "name": string,
  "data_type": string,
  "generator": "Character Sequence",
  // Generator-specific fields
  "character_sequence": string, // The pattern to use for the values.
  // End generator-specific fields
  "percent_null": integer,
  "virtual": boolean,
  // Advanced options
  "primary_key": boolean,
  "index": boolean,
  "seed": string,
  "postprocessing_sql": string
}
```

## Column From Another Table

Populates the column with values from a column in a different table.

```json
{
  "name": string,
  "data_type": string,
  "generator": "Column From Another Table",
  // Generator-specific fields
  "primary_key_entity": string, // Source table
  "primary_key_field": string,  // Source column
  "enable_where": boolean, // Select values based on criteria
  "foreign_key_field": string, // Other table column for criteria
  "value_field": string, // Current table column value for criteria
  // End generator-specific fields
  "group_key": string,
  "percent_null": integer,
  "virtual": boolean,
  // Advanced options
  "primary_key": boolean,
  "index": boolean,
  "seed": string,
  "postprocessing_sql": string
}
```

## Foreign Key

Makes the column a foreign key to another table.&#x20;

```json
{
  "name": string,
  "data_type": string,
  "generator": "Foreign Key",
  // Generator-specific fields
  "primary_key_entity": string, // References table
  "primary_key_field": string,  // References column
  "distribution": "none"|"fixed"|"from_column"|"burn-down"|"uniform"|"normal",
                  // The type of distribution to use
                  // None uses relative prevalence instead of cardinality
                  // burn-down is for Until column <= 0
  // -----------------------------------------------------------------------
  // None (relative prevalence)
  "primary_key_cardinality_field": string, // Relative prevalence column
  // -----------------------------------------------------------------------
  // Fixed distribution
  "exact_value": integer, // The number of times to use each row
  // -----------------------------------------------------------------------
  // From column distribution
  "primary_key_cardinality_field": string, // Column that contains the number
                                           // of times to use the row
  // -----------------------------------------------------------------------
  // Until column <= 0 distribution
  "value_field": string, // Column to check the value of
  "include_first_zero_or_less_row": boolean // Whether to create a foreign key
                                            // the first time the selected
                                            // column value is 0 or less.
  // -----------------------------------------------------------------------
  // Uniform distribution
  "min": integer, // Minimum number of times to use each row
  "max": integer, // Maximum number of times to use each row
  // -----------------------------------------------------------------------
  // Normal distribution
  "min": integer, // Minimum number of times to use each row
  "max": integer, // Maximum number of times to use each row
  "mean": string, // Mean number of times to use each row
  "std_dev": string, // Standard deviation
  // End generator-specific fields
  "percent_null": integer,
  "virtual": boolean,
  // Advanced options
  "primary_key": boolean,
  "index": boolean,
  "seed": string,
  "postprocessing_sql": string
}

```

## List

Populates the column from a provided list of values. You can optionally provide a weight for each value.

```json
{
  "name": string,
  "data_type": string,
  "generator": "List",
  // Generator-specific fields
  "values": text, // List of values to use for the column.
  // End generator-specific fields
  "group_key": string,
  "percent_null": integer,
  "virtual": boolean,
  // Advanced options
  "primary_key": boolean,
  "index": boolean,
  "seed": string,
  "postprocessing_sql": string
}
```

## Markov Chain

Sets the column value based on a configured list of allowed transitions between values.

```json
{
  "name": string, // Name of the column.
  "data_type": string,  // Database data type of the column values.
  "generator": "Markov Chain",
  "state_transitions": [ // List of allowed transitions.
    {
      "previous_value": string,  // The starting value for a transition.
      "next_value": string,  // The ending value for a transition.
      "probability": integer  // The percentage of times that a transition
                              // from previous_value goes to next_value.
    }
  ],
  "partition_by_field": string  // Column that determines when to start
                                // a new flow.
  "percent_null": integer,  // Percent of records to be null.
  "virtual": boolean,  // Whether to exclude the column from exported data.
  // Advanced options
  "primary_key": boolean, //Whether the column is a primary key.
  "index": boolean,  // Whether to index the column.
  "seed": string,  // The seed for random value generation.
                   // Setting this freezes the column until the seed changes.
  "postprocessing_sql": string, // SQL script to run after data generation.
}
```

## Rank

Assigns a rank value based on the values in 2 other columns.

```json
{
  "name": string,
  "data_type": string,
  "generator": "Rank",
  // Generator-specific fields
  "partition_by_field": string, // Partition by field
  "order_by_field": string,  // Order by field
  // End generator-specific fields
  "percent_null": integer,
  "virtual": boolean,
  // Advanced options
  "primary_key": boolean,
  "index": boolean,
  "seed": string,
  "postprocessing_sql": string
}
```

## Regular Expression

Produces a value that matches a regular expression that you provide. It uses the Peri-compatible [regular expression](https://www.regular-expressions.info/) syntax.

```json
{
  "name": string,
  "data_type": string,
  "generator": "Regular Expression",
  // Generator-specific fields
  "regex": string,  // Pattern
  // End generator-specific fields
  "percent_null": integer,
  "virtual": boolean,
  // Advanced options
  "primary_key": boolean,
  "index": boolean,
  "seed": string,
  "postprocessing_sql": string
}
```

## Row Number

Assigns an incrementing number to each row. Before Fabricate assigns the numbers, it can optionally sort the rows based on another column in the table.&#x20;

```json
{
  "name": string,
  "data_type": string,
  "generator": "Row Number",
  // Generator-specific fields
  "order_by_field": string,  // The name of the column to use to sort the rows
  // End generator-specific fields
  "percent_null": integer,
  "virtual": boolean,
  // Advanced options
  "primary_key": boolean,
  "index": boolean,
  "seed": string,
  "postprocessing_sql": string
}
```

## SQL

{% hint style="info" %}
The SQL generator is a premium feature. Free plan users have limited [access to premium features](https://docs.tonic.ai/fabricate/about-fabricate/fabricate-license-plans#premium-feature-access).
{% endhint %}

Uses a SQL expression to generate the value. The expression can refer to other columns and other tables.

```json
{ 
  "name": string,
  "data_type": string,
  "generator": "SQL",
  // Generator-specific fields
  "sql": string,  // SQL expression
  // End generator-specific fields
  "percent_null": integer,
  "virtual": boolean,
  // Advanced options
  "primary_key": boolean,
  "index": boolean,
  "seed": string,
  "postprocessing_sql": string
}
```

## Sum From Another Table

Populates a column with the sum of column values from rows in another table. To identify the rows to include, you provide join criteria.

```json
{ 
  "name": string,
  "data_type": string,
  "generator": "Sum From Another Table",
  // Generator-specific fields
  "primary_key_entity": string, // The table that contains the column to sum
  "value_field": string, // The column that contains the values to sum
  "foreign_key_field": string, // Sum table column for the join criteria
  "primary_key_field": string // Current table column for the join criteria
  // End generator-specific fields
  "percent_null": integer,
  "virtual": boolean,
  // Advanced options
  "primary_key": boolean,
  "index": boolean,
  "seed": string,
  "postprocessing_sql": string
}
```

## Sum Of Previous Rows

Adds together the values of a specified numeric column in rows that are before the current row.

```json
{ 
  "name": string,
  "data_type": string,
  "generator": "Sum Of Previous Rows",
  // Generator-specific fields
  "value_field": string, // Column to sum
  "partition_by_field": string, // Group by
  "order_by_field": string,  // Order by
  // End generator-specific fields
  "percent_null": integer,
  "virtual": boolean,
  // Advanced options
  "primary_key": boolean,
  "index": boolean,
  "seed": string,
  "postprocessing_sql": string
}
```

## Value From Previous Row

Populates a column with a value or values from another column in the previous row or rows.

```json
{
  "name": string,
  "data_type": string,
  "generator": "Value From Previous Row",
  // Generator-specific fields
  "value_field": string, // The column to get the value from
  "concat_type": "single"|"list"|"json", // How many previous values to retrieve
  "partition_by_field": string, // Partition by field
  "order_by_field": string,  // Order by field
  // End generator-specific fields
  "percent_null": integer,
  "virtual": boolean,
  // Advanced options
  "primary_key": boolean,
  "index": boolean,
  "seed": string,
  "postprocessing_sql": string
}
```
