Csv.Document
This topic applies to the Power Query Formula Language which can be used with Power Query and Power BI Desktop to build queries that mashup data. See the list of function categories.
Returns the contents of the CSV document as a table.
-
columns: If a record is specified anddelimiter,extraValues,encodingare null, all of parametersDelimiter,Columns,Encoding,CsvStyleandQuoteStyleare obtained from the record. -
delimitercan take a single character or a list; Comma is used if not specified or null. - Please refer to
ExtraValues.Typefor supported values of optionalextraValues. -
encodingspecifies the text encoding type.
Csv.Document(source as any, optional columns as any, optional delimiter as nullable text, optional extraValues as nullable number, optional encoding as nullable number) as table
| Argument | Description |
|---|---|
| source | The CSV file to parse. |
| optional columns | Optional column names. |
| optional delimiter | Delimiters between values. |
| optional extraValues | Specification for extra value handling. |
| optional encoding | Encoding value. |
- QuoteStyle.Csv is used during the parsing. With this QuoteStyle, a double quote character is used to demarcate such regions, and a pair of double quote characters is used to indicate a single double quote character within such a region.
//Assume the following SalesForce contacts CSV file.
FirstName,LastName,Title,ReportsTo.Email,Birthdate,Description
Tom,Jones,Senior Director,buyer@salesforcesample.com,1940-06-07Z,"Self-described as ""the top"" branding guru on the West Coast"
Ian,Dury,Chief Imagineer,cto@salesforcesample.com,,"World-renowned expert in fuzzy logic design.
Influential in technology purchases."
let
Source = Csv.Document(File.Contents("C:\Projects\Examples\SalesForceContacts.txt"),[Delimiter=",",Encoding=1252]),
#"First Row as Header" = Table.PromoteHeaders(Source),
#"Changed Type" = Table.TransformColumnTypes
(#"First Row as Header",{{"FirstName", type text},
{"LastName", type text}, {"Title", type text}, {"ReportsTo.Email", type text}, {"Birthdate", type datetime}, {"Description", type text}}),
#"Removed Columns" = Table
.RemoveColumns(#"Changed Type", {"Description", "Birthdate"})
in
#"Removed Columns"
equals
| FirstName | LastName | Title | ReportsTo.Email |
|---|---|---|---|
| Tom | Jones | Senior Director | buyer@salesforcesample.com |
| Ian | Dury | Chief Imagineer | cto@salesforcesample.com |
Show: