> For the complete documentation index, see [llms.txt](https://cgps.gitbook.io/data-flo/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cgps.gitbook.io/data-flo/reference-guide/add-column.md).

# add-column

## Description

<mark style="color:purple;">`add-column`</mark> *adaptor can be used to create a new column at the end of a datatable.*

By default, the cells on the newly added column will be empty, this can be changed by setting a `value`. To move the new column to a different position in the datatable, use the [`select-columns` adaptor](/data-flo/reference-guide/select-columns.md) to reorder the columns.

To add different values to each row of the new column, use the [`map-column-values`](/data-flo/reference-guide/map-column-values.md) adaptor.&#x20;

## Inputs

**`data`**\
Type: `datatable`\
Required: Yes\
The datatable to which the new column will be added.

**`column name`**\
Type: `text`\
Required: Yes\
The name of the new column to be added.

**`value`**\
Type: `text`\
Required: No\
A value to be added to the column cells. If unspecified, empty values will be added.

## Outputs

**`data`**\
Type: `datatable`\
A datatable with the new column added.

## Examples

### Example 1: Default behaviour.

#### Inputs:

`data`

<table><thead><tr><th width="100.5339366515837">Month</th><th width="152">Sales (USD)</th></tr></thead><tbody><tr><td>Jan</td><td>1458</td></tr><tr><td>Feb</td><td>9874</td></tr></tbody></table>

`column name`: Year

#### Outputs:

`data`:

<table><thead><tr><th width="149.32307692307694">Month</th><th width="126">Sales (USD)</th><th width="100">Year</th></tr></thead><tbody><tr><td>Jan</td><td>1458</td><td></td></tr><tr><td>Feb</td><td>9874</td><td></td></tr></tbody></table>

-> Added column `Year` to the datatable with empty values.

### Example 2: Add column with `value`.

Inputs:

`data`:

<table><thead><tr><th width="132.5339366515837">Month</th><th width="142">Sales (USD)</th></tr></thead><tbody><tr><td>Jan</td><td>1458</td></tr><tr><td>Feb</td><td>9874</td></tr></tbody></table>

`column name`: Year

`value`: 2024

#### Outputs:

`data`:

<table><thead><tr><th width="134.5">Month</th><th width="126">Sales (USD)</th><th width="127">Year</th></tr></thead><tbody><tr><td>Jan</td><td>1458</td><td>2024</td></tr><tr><td>Feb</td><td>9874</td><td>2024</td></tr></tbody></table>

-> Added column `Year` to the datatable with the value `2024`.

## Use Cases

* Add a column for data sources to the datatables before merging to track data origin
* Use Data-flo to create a spreadsheet including some existing data, as well as some standardised empty columns for users to fill in later.
* When joining two datatables, and one is missing one column which is found in the second, this adaptor can be used to provide values for the missing column.
* During data cleaning or transformation, users may need to transform the data in a way that requires the creation of a new column in order to retain the originally formatted data in the original column. This can include tasks like formatting dates, converting units, or categorizing data.
