Examples

M CSV Import

Importing CSV Data

M CSV import query parses files with Csv.Document.

Introduction to M CSV Import

Importing CSV files into Power Query M is a common task for data transformation and analysis. The function used for this purpose in M is Csv.Document. This guide will walk you through the process of importing CSV files and parsing them effectively using M's Csv.Document function.

Basic Usage of Csv.Document

The Csv.Document function is used to read CSV data into a tabular format. It takes a binary content input and outputs a table. Here is a simple usage example:

Parameters of Csv.Document

Csv.Document accepts several optional parameters to customize how CSV files are parsed:

  • Delimiter: Specifies the character that separates values (e.g., "," or ";").
  • Encoding: Defines the text encoding (e.g., UTF-8 or ASCII).
  • QuoteStyle: Determines how quotes are handled in the CSV file.

Handling Different Encodings

CSV files can be encoded in different formats. The Encoding parameter in Csv.Document allows you to specify the correct encoding to ensure data is read correctly. For example, to read a file encoded in UTF-16, you can set Encoding=1200.

Using Csv.Document with Web Sources

In addition to local files, Csv.Document can also parse CSV data from web sources. This can be useful for automating data import from online datasets:

Conclusion

Using Csv.Document in M makes it easy to import and parse CSV files, whether they are stored locally or online. By understanding the parameters and their functionalities, you can handle various CSV formats efficiently in your data transformation tasks.