---
title: "Formula - csv: Extract a Column from Delimited Text"
description: The csv Formula function returns the values of one zero-based column of CSV or other delimited text, skipping header rows and comment lines. Includes syntax, parameters, and examples from body, context, and jsonPath.
---

# :fa-function: Formula - csv

The `csv` [Formula][] function returns the values of one column of CSV or other delimited text, after skipping header rows and comment lines.

![Cut the order lines out of an Order Confirmation CSV with regex, then read their descriptions with csv, animated walkthrough (7.12)][4]  
*Animated walkthrough: the Order Confirmation of the [Order-to-Cash demo][] is a CSV file with a header, a details and a footer section. `regex('LineNumber,[^\n]*(\n\d+,[^\n]*)+', body)` cuts out the order lines with their header row. `csv(1, ',', 2, '#', regex(…))` skips that header row and returns column `2` (the third column): `Demo Widget`, `Demo Gadget` and `Demo Sprocket`.*  

## :fa-code: Syntax

```text
csv(headerRowsToSkip, 'delimiter', columnIndex, 'commentSymbol', content)
```

### Parameters

|Parameter|Required|Description|  
|---|---|---|  
|`headerRowsToSkip`|Yes|Number of rows to skip at the top, such as a header row. A number, without quotes.|  
|`'delimiter'`|Yes|The character that separates columns, such as `','` or `';'`.|  
|`columnIndex`|Yes|The column to return, zero-based: `0` is the first column, `1` the second. A number, without quotes.|  
|`'commentSymbol'`|Yes|Lines that start with this character are ignored, such as `'#'`.|  
|`content`|Yes|The delimited text: [body][], [context][Context], or the result of another function (see [Formula language rules][]).|  

### Returns

One value per remaining row: the value in column `columnIndex`, with surrounding double quotes removed. Duplicates are collapsed. Rows that are skipped, blank, or start with the comment symbol return nothing.

## :fa-list-ol: Examples

### Example 1: Return the second column of the message body

#### Input

```text
"face","suit","value"
"king","spades",13
"queen","spades2",12
#"jack","spades3",11
"ten","spades4",10
"nine","spades5",9
#"twenty","clown",10
"eight","spades6",8
"seven","spades7",7
```

#### Formula

```text
csv(2, ',', 1, '#', body)
```

#### Result

```text
spades2
spades4
spades5
spades6
spades7
```

![Formula csv expression returning five suit values from a CSV message body in the Test Expression tab][1]  
*The first two rows (`face` and `king`) are skipped, the two `#` lines are ignored, and column `1` (the second column) is returned.*  

### Example 2: Highest value in a context property

#### Input

The Message Context key `Ids` has this value:

```text
"face","suit","value"
"king","spades","13"
"queen","spades2","12"
#"jack","spades3","666"
"ten","spades4","10"
```

#### Formula

```text
max(csv(1, ',', 2, '#', context('Ids')))
```

#### Result

```text
13
```

![Formula max of csv on the Ids context property returning 13 in the Test Expression tab (7.12)][2]  
*`csv` returns 13, 12, and 10 from the third column; the commented `666` row is ignored, so [max][] returns `13`.*  

### Example 3: CSV embedded in a JSON field

#### Input

```json
{
    "name": "JSONFile",
    "description": "TestFile",
    "content": "\"face\",\"suit\",\"value\"\n\"jack\",\"spades3\",11\n\"ten\",\"spades4\",10\n\"nine\",\"spades5\",9\n\"eight\",\"spades6\",8\n\"seven\",\"spades7\",7"
}
```

#### Formula

```text
csv(4, ',', 1, '#', jsonPath('$.content', body))
```

#### Result

```text
spades6
spades7
```

![Formula csv over jsonPath content returning spades6 and spades7 in the Test Expression tab][3]  
*[jsonPath][] returns the CSV text of the `content` field; `csv` skips four rows (header, jack, ten, nine) and returns the second column of the rest.*  

## :fa-circle-info: Notes

* Rows and columns count differently: `headerRowsToSkip` is a count of rows, `columnIndex` is zero-based.
* Every row after the skipped ones needs at least `columnIndex + 1` columns. One shorter row fails the whole expression, and no value is returned for the other rows either. The Test tab then says, for example: *Column index 2 is out of range on row 2, which has 1 column (the first column is 0).*
* A `headerRowsToSkip` that isn't smaller than the number of rows fails too: *The number of header rows to skip (20) is not smaller than the number of rows (12).*
* A file with several sections, such as a header, details, and footer, has rows of different widths. Cut out the section you need with [regex][] first, and run `csv` on that, as in the walkthrough above.
* For fixed-width records, use the [Flat File Fixed Width plugin][]. When one column is all you need and nothing has to be nested, the [Flat File CSV plugin][] does the job without a formula; see [Choose a plugin][].

## :fa-hand-point-right: Next Steps

* :fa-magnifying-glass-plus: [Add or manage Search Field][]  
* :fa-flask: [Test Your Expression][]  
* :fa-hard-drive: [Add or manage Log View][]  

## :fa-link-horizontal: Related Topics

* :fa-filter: [Extract functions][Extract Group]  
* :fa-sitemap: [jsonPath][]  
* :fa-key: [jsonPathKey][]  
* :fa-text-slash: [regex][]  
* :fa-layer-group: [regexGroup][]  
* :fa-database: [sqllookup][]  
* :fa-code: [xPath][]  
* :fa-code: [xPath2][]  
* :fa-function: [Formula][]  
* :fa-scroll: [Formula language rules][]  
* :fa-puzzle-piece: [Search Field Expressions][]  
* :fa-magnifying-glass: [Flat File CSV plugin][]  
* :fa-magnifying-glass: [Flat File Fixed Width plugin][]  

[1]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/csv_simplebody_.png
[2]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/MaxFromCSVContext.png
[3]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/csv_FunctionAsContent.png
[4]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/Formula_Csv.gif

[Add or manage Log View]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/Add%20or%20Manage%20Log%20View.md
[Add or manage Search Field]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md
[body]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Source/body.md
[Choose a plugin]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Overview.md#fa-signs-post-choose-a-plugin
[Context]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Source/context.md
[Extract Group]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md#extract
[Flat File CSV plugin]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Flat%20File%20CSV.md
[Flat File Fixed Width plugin]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Flat%20File%20Fixed%20Width.md
[Formula]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md
[Formula language rules]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md#fa-scroll-formula-language-rules
[jsonPath]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/jsonPath.md
[jsonPathKey]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/JsonPathKey.md
[max]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/max.md
[Order-to-Cash demo]:{ndr}/Repository%20Model/BPMs/Examples/Order-to-Cash/Generate-O2C-Demo-Data.md
[regex]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/regex.md
[regexGroup]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/regexGroup.md
[Search Field Expressions]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Overview.md
[sqllookup]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/sqllookup.md
[Test Your Expression]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md#test-your-expression
[xPath]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/xPath.md
[xPath2]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/xPath2.md