Sub topic 5
Connecting to a CSV file: delimiter, encoding, and headers
This chapter assumes you know the Power BI Desktop interface and can open the Power Query Editor. You should also know what an applied step is. If a CSV loads as one wide column or shows garbled characters, the cause is usually one of three settings: the delimiter, the encoding, or the header row.
How the Text/CSV connector works
Choose Get Data > Text/CSV and select the file. Power BI shows a preview with three dropdowns: File Origin (encoding), Delimiter, and data type detection. The preview guesses each of these from the first rows of the file. A wrong guess is the most common source of bad CSV loads, so check the preview before you select Transform Data.
In Power Query, the connector becomes a call to Csv.Document. Its options map to what you saw in the preview:
| Option | Meaning | Typical value |
|---|---|---|
| `Delimiter` | Character that separates fields | `","`, `";"`, or `"#(tab)"` |
| `Encoding` | Code page number of the file's text encoding | `65001` for UTF-8 |
| `QuoteStyle` | How quoted fields are handled | `QuoteStyle.Csv` |
A worked example
This query reads a UTF-8, comma-delimited file, promotes the first row to headers, and sets column types.
let
Source = Csv.Document(File.Contents("C:\Data\orders.csv"), [Delimiter = ",", Encoding = 65001, QuoteStyle = QuoteStyle.Csv]),
Promoted = Table.PromoteHeaders(Source, [PromoteAllScalars = true]),
Typed = Table.TransformColumnTypes(Promoted, {{"OrderID", Int64.Type}, {"OrderDate", type date}})
in
TypedEach line is an applied step. Source reads the raw text and splits it into columns. Promoted turns the first row into column names. Typed converts text to real types.
Delimiter
The delimiter must match the file. Many European regional settings export with a semicolon because the comma is the decimal separator. If you leave the delimiter as a comma on such a file, every row lands in a single column. Fix it by changing the dropdown in the preview, or by editing Delimiter in the Source step. For a tab-separated file, use "#(tab)".
Encoding
Encoding tells Power Query how to turn bytes into characters. Use 65001 for UTF-8. Many files saved from older Windows tools use 1252 (Western European). If names such as "José" appear as "José", the file is UTF-8 but was read with another encoding, or the reverse. Change File Origin in the preview, or edit Encoding in the formula bar.
Headers
A CSV has no real header concept. The first line is just another row. Power Query reads every row as data, which is why Table.PromoteHeaders is a separate step. Two things can go wrong:
- The file has title or metadata lines above the real header. Use Remove Top Rows before promoting headers.
- Promoting headers before types are set is correct. Setting types first would try to convert header text such as "OrderDate" into a date and produce errors.
PromoteAllScalars = true makes Power Query promote numbers and dates in the header row too, and convert them to text names.
Quoted fields
If a text field contains a comma or a line break, the file wraps it in double quotes. QuoteStyle.Csv honors that quoting. QuoteStyle.None ignores it and splits the field at every comma, which shifts the remaining columns. Use QuoteStyle.Csv unless you have a specific reason not to.
Exercise
A semicolon-delimited export loads into Power BI as a single column, and the name "Zoë" appears as "Zoë". Which two options in the Csv.Document call do you change, and to what?
Show answer
Change Delimiter to ";" so the fields split into separate columns. Set Encoding to 65001 (UTF-8) so the text is decoded correctly. Then run Table.PromoteHeaders if the first row is still data.