Csv.Document

Accessing Data

Parses CSV text into a table.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

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 table

Parameters

NameTypeRequiredDescription
sourceanyYesThe CSV text or binary content to parse.
columnsanyNoThe number of columns, a list of column names, a table type, or an options record.
delimiteranyNoThe column delimiter. Defaults to comma (",").
extraValuesnumberNoHow to handle extra values per row (ExtraValues.Error, ExtraValues.Ignore, or ExtraValues.List).
encodingnumberNoThe text encoding of the source (e.g., TextEncoding.Utf8).

Return Value

tableA 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:

``powerquery 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, and QuoteStyle.

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
    Promoted
Result
Name
Age
City
1Alice30Seattle
2Bob25Portland

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])
Result
Product
Price
1Widget9.99
2Gadget14.50

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks