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 and delimiter, extraValues, encoding are null, all of parameters Delimiter, Columns, Encoding, CsvStyle and QuoteStyle are obtained from the record.
  •  
  •  delimiter can take a single character or a list; Comma is used if not specified or null.
  •  
  • Please refer to ExtraValues.Type for supported values of optional extraValues.
  •  
  •  encoding specifies 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  

ArgumentDescription
sourceThe CSV file to parse.
optional columnsOptional column names.
optional delimiterDelimiters between values.
optional extraValuesSpecification for extra value handling.
optional encodingEncoding 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  

FirstNameLastNameTitleReportsTo.Email
TomJonesSenior Directorbuyer@salesforcesample.com
IanDuryChief Imagineercto@salesforcesample.com
Show: