Csv.Document
Accessing DataParses CSV text into a table.
Syntax
Csv.Document(source as any, optional columns as any, optional delimiter as any, optional extraValues as nullable number, optional encoding as nullable number) as tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
source | any | Yes | The CSV text or binary content to parse. |
columns | any | No | The number of columns, a list of column names, a table type, or an options record. |
delimiter | any | No | The column delimiter. Defaults to comma (","). |
extraValues | number | No | How to handle extra values per row (ExtraValues.Error, ExtraValues.Ignore, or ExtraValues.List). |
encoding | number | No | The text encoding of the source (e.g., TextEncoding.Utf8). |
Return Value
table — A table parsed from the CSV content.
Remarks
Csv.Document parses CSV (comma-separated values) text or binary content into a table. It is most commonly used in combination with File.Contents or Web.Contents to load external CSV files:
Csv.Document(File.Contents("C:\Data\sales.csv"), [Delimiter = ",", Encoding = TextEncoding.Utf8])The columns parameter accepts several forms:
- A number — the expected column count (columns are named Column1, Column2, etc.).
- A list of text — column names to assign.
- A table type — defines both column names and types in one step.
- An options record — with fields like
Delimiter,Encoding,CsvStyle, andQuoteStyle.
When the first row contains headers, wrap the result in Table.PromoteHeaders to use it as column names.
CsvStyle.QuoteAlways and CsvStyle.QuoteAfterDelimiter control how quoted fields are handled. QuoteStyle.Csv (the default) treats double-quotes as field wrappers; QuoteStyle.None treats them as literal characters.
Examples
Example 1: Parse inline CSV text
let
CsvText = "Name,Age,City#(lf)Alice,30,Seattle#(lf)Bob,25,Portland",
Parsed = Csv.Document(CsvText, [Delimiter = ","]),
Promoted = Table.PromoteHeaders(Parsed, [PromoteAllScalars = true])
in
PromotedThe final output — a table with named columns and two data rows parsed from the inline CSV string.
Name | Age | City | |
|---|---|---|---|
| 1 | Alice | 30 | Seattle |
| 2 | Bob | 25 | Portland |
Example 2: Parse with a typed schema
let
CsvText = "Product,Price#(lf)Widget,9.99#(lf)Gadget,14.50",
Schema = type table [Product = text, Price = number],
Parsed = Csv.Document(CsvText, Schema)
in
Table.PromoteHeaders(Parsed, [PromoteAllScalars = true])The final output — Table.PromoteHeaders promotes the first row as column names, yielding a two-row table with Product and Price columns.
Product | Price | |
|---|---|---|
| 1 | Widget | 9.99 |
| 2 | Gadget | 14.50 |