The Csv.Document function in Power Query reads the contents of a CSV file and turns it into a table. You give it the file (or some CSV text), and it splits each line into rows and each comma into columns.
It also has options for the stuff that usually goes wrong with CSV files, like semicolons instead of commas, garbled accented letters, files without headers, and report titles sitting above the data.
In this article, I’ll show you how Csv.Document works with practical examples that cover each of these.
Follow along with the example file
Csv.Document Function Examples.zip
Csv.Document Function 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
- source – the CSV content you want to read. Most of the time, this is a file you read with the File.Contents function, like
File.Contents("C:\Data\Orders.csv"). It can also be CSV text typed straight into the formula. - columns (optional) – the number of columns, a list of column names, or an options record. In practice, you’ll almost always pass an options record here, like
[Delimiter=";",Encoding=1252]. - delimiter (optional) – the character that separates the values. The default is a comma.
- extraValues (optional) – what to do when a row has more values than there are columns: raise an error, ignore the extra values, or collect them into a list.
- encoding (optional) – the text encoding of the file, as a code page number. The default is 65001 (UTF-8).
When you pass an options record as the second argument, it can have these fields: Delimiter (the separator, default comma), Columns (a number of columns or a list of column names), and Encoding (the code page, default 65001).
It can also have QuoteStyle (whether line breaks inside quotes are part of the value, default QuoteStyle.Csv).
Two more fields you’ll rarely need are ExtraValues (the same setting as the extraValues argument) and CsvStyle (whether a quote mark only counts right after a delimiter, which is the default, or anywhere in a value).
What it returns: A table with one row for each line in the CSV and one column for each value. The columns are named Column1, Column2, and so on, and every value comes in as text.
The Csv.Document function is part of the core Power Query M library, so you can use it anywhere you have Power Query, in Excel and in Power BI.
When to Use the Csv.Document Function
Use this function when you need to:
- Load a CSV or text file into Power Query and control exactly how it’s read
- Read files that use a semicolon, tab, or another character instead of a comma
- Fix accented letters that show up as odd symbols after import
- Give column names to a CSV file that has no header row
- Skip report titles or notes sitting above the actual data
- Combine every CSV file in a folder into one table
How the Example Files Work
Csv.Document reads separate files, so this download is a zip. It has the examples workbook with all the queries, seven CSV files, and a Monthly Expenses folder with three more CSV files for the last example.
The queries don’t type the full file path into every formula. Instead, they use a parameter called CsvFolder that holds the path to the folder with the CSV files, and each query adds the file name to it, like CsvFolder & "Workshop Registrations.csv".
If you unzip the download into C:\Users\Public\Documents, you get a folder called C:\Users\Public\Documents\Csv.Document Function Examples, and the queries work as they are.
Check that the CSV files sit directly inside that folder. If they end up one folder deeper (inside a second folder with the same name), the queries can’t find them, so move the files up a level or change the parameter.
If you save the files somewhere else, open the Power Query Editor, go to Home > Manage Parameters, and change CsvFolder to your folder path. Keep the backslash at the end, since the queries add the file name right after it.
In your own file, you can skip the parameter and type the path straight into the formula, like File.Contents("C:\Data\Orders.csv").
Example 1: Read a CSV File into Power Query
Let’s start with the basic use. Workshop Registrations.csv has six workshop bookings, with the registration ID, date, attendee, workshop, seats, and amount for each one.
Open the examples workbook (it has the CsvFolder parameter), or the matching Example query in it. In your own file, use the full file path instead of CsvFolder & "...".
To build the query yourself, go to Data > Get Data > From Other Sources > Blank Query. In the Power Query Editor, open the Advanced Editor (Home > Advanced Editor) and use this code:
let
Source = Csv.Document(File.Contents(CsvFolder & "Workshop Registrations.csv"))
in
Source
Result: A table with seven rows and six columns named Column1 to Column6, with the headers (Reg ID, Date, Attendee, Workshop, Seats, Amount) in the first row

Here, the File.Contents function reads the file from disk, and Csv.Document splits it into rows and columns. Since we didn’t pass any options, it uses a comma as the separator and reads the file as UTF-8.
Csv.Document doesn’t know that the first line holds the headers, so it keeps that line as regular data and names the columns Column1, Column2, and so on. It also brings in every value as text, including the dates and numbers.
Both are easy to fix, and that’s what the next example does.
Example 2: Use the First Row as Headers and Set the Data Types
In most CSV files, the first line holds the column headers. So right after Csv.Document, you’ll usually promote that line to headers and set the data types.
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Csv.Document(File.Contents(CsvFolder & "Workshop Registrations.csv")),
#"Promoted Headers" = Table.PromoteHeaders(Source,[PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date",type date},{"Seats",Int64.Type},{"Amount",type number}})
in
#"Changed Type"
Result: The six bookings with proper headers, the dates showing as 1/5/2026 to 1/15/2026, and Seats and Amount as numbers

Here, the Table.PromoteHeaders function turns the first row into the column headers. Then the Table.TransformColumnTypes function changes Date to a date, Seats to a whole number, and Amount to a decimal number.
The dates in this file are written as 2026-01-05 (year, month, day), and that format converts the same way on any computer.
The result shows them in your computer’s date format, so you see 1/5/2026 on a US setup and 05/01/2026 on a UK one, but the date is the same.
Example 3: Read a File That Uses Semicolons
Not every CSV file uses commas. Files exported on computers with European regional settings often use semicolons, because the comma is already used as the decimal separator.
Supplier Price List.csv is one of those. Its lines look like this:
Article No;Description;Unit Price;Stock
DE-2201;Desk Lamp;24,90;140
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Csv.Document(File.Contents(CsvFolder & "Supplier Price List.csv"),[Delimiter=";"]),
#"Promoted Headers" = Table.PromoteHeaders(Source,[PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Unit Price",type number},{"Stock",Int64.Type}},"de-DE")
in
#"Changed Type"
Result: Five products with Article No, Description, Unit Price, and Stock columns, and the prices showing as 24.9, 59.5, 189, 12.75, and 34.2

Here, [Delimiter=";"] tells Csv.Document to split each line at the semicolons.
Without it, Csv.Document splits at commas and takes the number of columns from the first line. Here that’s the header line, which has no commas, so the table gets one column.
Every product row then shows the error “There were more columns in the result than expected”, because the decimal comma in each price splits that line into two values.
The prices need one more thing. If you convert “24,90” to a number on a US setup, Power Query ignores the comma and you get 2490, which is a wrong result with no error to warn you.
That’s why the last argument of Table.TransformColumnTypes is "de-DE". It tells Power Query to read the numbers the German way, where the comma is the decimal separator, so 24,90 becomes 24.9.
For a tab-separated file, use [Delimiter="#(tab)"]. The #(tab) is how you write a tab character in M.
Example 4: Fix Garbled Accented Letters with Encoding
This one trips up a lot of people. You load a file, and the accented letters show up as odd symbols.
Cafe Menu.csv has five menu items with names like Café Latte and Crème Brûlée. It was saved in the Windows-1252 encoding (often called ANSI), not in UTF-8.
Let’s first read it without setting the encoding. Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Csv.Document(File.Contents(CsvFolder & "Cafe Menu.csv")),
#"Promoted Headers" = Table.PromoteHeaders(Source,[PromoteAllScalars=true])
in
#"Promoted Headers"
Result: The five menu items, with every accented letter replaced by a � symbol (Caf� Latte, Cr�me Br�l�e)

Here, Csv.Document read the file as UTF-8, which is its default. But the file was saved in Windows-1252, where letters like é are stored differently, so Power Query couldn’t read them and put a � in their place.
To fix it, tell Csv.Document which encoding the file uses. Windows-1252 is code page 1252, so use this code instead:
let
Source = Csv.Document(File.Contents(CsvFolder & "Cafe Menu.csv"),[Encoding=1252]),
#"Promoted Headers" = Table.PromoteHeaders(Source,[PromoteAllScalars=true])
in
#"Promoted Headers"
Result: The five menu items with their accents intact: Café Latte, Crème Brûlée, Jalapeño Bagel, Açaà Bowl, and Piña Colada Smoothie

Now every letter shows correctly, because Power Query reads the bytes the same way they were saved.
You can also hit the opposite problem.
If your query has Encoding=1252 but the file is really UTF-8, Café shows up as Café. In that case, change the encoding to 65001 (or remove it, since 65001 is the default).
Example 5: Name the Columns of a File with No Header Row
Some systems export CSV files with only the data and no header row. Meter Readings.csv is like that, and its lines look like this:
2026-02-01,MTR-301,18452
2026-02-01,MTR-302,9310
Instead of adding a step to rename Column1, Column2, and Column3, you can give Csv.Document the column names directly. Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Csv.Document(File.Contents(CsvFolder & "Meter Readings.csv"),[Columns={"Reading Date","Meter ID","Reading"}]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Reading Date",type date},{"Reading",Int64.Type}})
in
#"Changed Type"
Result: Six meter readings with the columns Reading Date, Meter ID, and Reading

Here, the Columns field takes a list of names, and Csv.Document uses them in order for the columns in the file. Since the first line is already data, there’s no header row to promote.
The list also sets how many columns you get. If you list fewer names than the file has values, the extra values are dropped, so make sure you have one name for each column you want to keep.
Example 6: Get a New Column That Doesn’t Show Up
Here’s a problem you might hit with a query that worked fine for months. Someone adds a new column to the CSV file, you refresh, and the new column just isn’t there.
Survey Responses.csv used to have five columns, and now it has a sixth one, Department, at the end. Below is the query that was set up before Department was added:
let
Source = Csv.Document(File.Contents(CsvFolder & "Survey Responses.csv"),[Columns=5]),
#"Promoted Headers" = Table.PromoteHeaders(Source,[PromoteAllScalars=true])
in
#"Promoted Headers"
Result: Five survey responses with Response ID, Respondent, Rating, Comment, and Submitted columns, and no Department column

Here, Columns=5 tells Csv.Document to read exactly five columns, so it drops the sixth value on every line.
You may see this in a query you never typed by hand. Microsoft’s documentation for the Text/CSV connector (written for Power BI Desktop) notes that the import writes a Columns number based on how many columns the file had when you first imported it.
To pick up all the columns, remove the Columns field:
let
Source = Csv.Document(File.Contents(CsvFolder & "Survey Responses.csv")),
#"Promoted Headers" = Table.PromoteHeaders(Source,[PromoteAllScalars=true])
in
#"Promoted Headers"
Result: The same five responses with all six columns, including Department

Without Columns, Csv.Document counts the values in the first line of the file, which is the header row here. So it finds six and reads all six.
If you’d rather keep a fixed number, change it to 6. A number larger than the real column count is safe too, as the extra columns just come in empty.
Follow along with the example file
Csv.Document Function Examples.zip
Example 7: Handle Commas and Line Breaks Inside Quotes
Sometimes a value itself has a comma in it, like an address. CSV files handle this by putting the value in double quotes, and the quotes can even hold a line break.
Delivery Notes.csv has four deliveries with an address and delivery instructions. Its lines look like this:
D-501,Tara Taylor,"14 Oak Street, Apt 3",Leave at front desk
D-502,Jeremy Simmons,220 Pine Road,"Call on arrival
Gate code 4471"
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Csv.Document(File.Contents(CsvFolder & "Delivery Notes.csv"),[QuoteStyle=QuoteStyle.Csv]),
#"Promoted Headers" = Table.PromoteHeaders(Source,[PromoteAllScalars=true])
in
#"Promoted Headers"
Result: Four deliveries in four columns, with “14 Oak Street, Apt 3” in one Address cell and both lines of the D-502 instructions in one cell

Here, Csv.Document treats everything inside the double quotes as one value, so the comma in the address doesn’t start a new column.
The line break is handled by QuoteStyle=QuoteStyle.Csv. It tells Csv.Document that a line break inside quotes is part of the value, so D-502 stays one row.
This is also the default, so you’d get the same result without the option, but writing it out makes the setting easy to see.
If the option says QuoteStyle=QuoteStyle.None instead, Csv.Document ignores the quotes when it looks for line breaks. Then D-502 splits into two rows, and the second line of its instructions (Gate code 4471) starts a row of its own.
So if quoted values in your file break into extra rows, check the Source step of your query and change QuoteStyle.None to QuoteStyle.Csv.
Example 8: Skip Title Rows Above the Data
Bank and accounting systems often add a few lines of report details above the real data. Bank Statement.csv starts like this:
Account Statement
Account: Checking 4821
Period: Mar 1 2026 to Mar 31 2026
Date,Description,Amount,Balance
2026-03-03,Grocery Store,-86.40,2363.60
If you read this file with just Csv.Document(File.Contents(...)), the result has a single column. The title lines come in fine, but the header row and every transaction row show an error: “There were more columns in the result than expected.”
That happens because, when you don’t set Columns, Csv.Document counts the values in the first line to decide how many columns the table has.
The first line here is the title, Account Statement, which has only one value, so every line with four values has too many.
The fix is to set the number of columns yourself, then remove the title rows. Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Csv.Document(File.Contents(CsvFolder & "Bank Statement.csv"),[Columns=4]),
#"Removed Top Rows" = Table.Skip(Source,4),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows",[PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date",type date},{"Amount",type number},{"Balance",type number}},"en-US")
in
#"Changed Type"
Result: Five transactions with Date, Description, Amount, and Balance columns, starting with 3/3/2026, Grocery Store, -86.4, 2363.6

Here’s what each step does:
- Source reads the file with
Columns=4, so every line gets four columns. The title lines fill the first column and leave the other three empty. - Removed Top Rows uses the Table.Skip function to drop the first four rows (the three title lines and the blank line under them).
- Promoted Headers turns the Date, Description, Amount, Balance line into the headers.
- Changed Type sets Date as a date and Amount and Balance as numbers. The
"en-US"at the end makes sure 2363.60 is read with a period as the decimal separator, even on a computer with European regional settings.
This code expects exactly four rows above the header row. If that number changes from file to file, Table.Skip also accepts a condition instead of a number, so Table.Skip(Source,each [Column1]<>"Date") skips rows until it reaches the header row.
Example 9: Read CSV Text Instead of a File
Csv.Document doesn’t need a file. You can give it CSV text directly, which is handy for testing an option or for building a small table right inside a query.
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Csv.Document("Size,Stock#(cr)#(lf)Small,14#(cr)#(lf)Medium,22#(cr)#(lf)Large,9"),
#"Promoted Headers" = Table.PromoteHeaders(Source,[PromoteAllScalars=true])
in
#"Promoted Headers"
Result: A table with Size and Stock columns and three rows: Small 14, Medium 22, and Large 9

Here, #(cr)#(lf) is how you write a line break in M text (a carriage return followed by a line feed). So the text holds four lines, and Csv.Document splits it the same way it would split a file.
The Stock values come in as text here too, so add a Table.TransformColumnTypes step if you need them as numbers.
Example 10: Combine All CSV Files in a Folder
This last one is a very common task. You get one CSV file each month with the same columns, and you want all of them in one table.
The Monthly Expenses folder has three files (2026-01.csv, 2026-02.csv, and 2026-03.csv), each with Date, Category, and Amount columns. Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Folder.Files(CsvFolder & "Monthly Expenses"),
#"CSV Files" = Table.SelectRows(Source,each Text.Lower([Extension])=".csv"),
#"Parsed CSV" = Table.AddColumn(#"CSV Files","Data",each Table.PromoteHeaders(Csv.Document([Content]),[PromoteAllScalars=true])),
#"Kept Columns" = Table.SelectColumns(#"Parsed CSV",{"Name","Data"}),
#"Expanded Data" = Table.ExpandTableColumn(#"Kept Columns","Data",{"Date","Category","Amount"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Data",{{"Date",type date},{"Category",type text},{"Amount",type number}})
in
#"Changed Type"
Result: One table with eight expenses from the three files, with a Name column showing which file each row came from

Here’s what each step does:
- Source uses the Folder.Files function to list every file in the folder, with each file’s content in the Content column. It’s the same function you’d use to list file names in a folder.
- CSV Files uses the Table.SelectRows function to keep only the files that end in .csv. The Text.Lower function catches files saved as .CSV too.
- Parsed CSV runs Csv.Document on each file’s content and promotes its headers, so the new Data column holds one table per file.
- Kept Columns and Expanded Data keep the file name and the data, then stack all the rows with the Table.ExpandTableColumn function.
- Changed Type sets the data types, because the expanded columns come in with no data type (the ABC123 icon).
To add April, drop its file into the folder and refresh. The Expanded Data step lists the column names, so if a new column shows up in the monthly files, add its name to that list too.
If your files don’t all have the same headers, see how to combine CSV files with different column headers.
Other Excel Articles You May Also Like:
- Excel.Workbook – Use Excel.Workbook in Power Query M to read sheets and tables from a workbook.
- Web.Contents – Use Web.Contents in Power Query M to get data from a URL or API.
- Splitter.SplitTextByDelimiter – Use Splitter.SplitTextByDelimiter in Power Query M to split text.
- Json.Document – Use Json.Document in Power Query M to parse JSON text.
- Table.FromList – Use Table.FromList in Power Query M to turn a list into a table.
- Table.FromRecords – Use Table.FromRecords in Power Query M to build a table from records.
- Table.Combine – Use Table.Combine in Power Query M to stack multiple tables into one by appending rows.
- Sql.Database – Use Sql.Database in Power Query M to connect to a SQL Server database.