Skip to content
BI Data

CSV → Power Query M Import Generator

About this tool

Analyze CSV structure and generate a Power Query M import snippet for Power BI or Excel. Review inferred types and update the file path before running the query.

Features:

  • Type inference — detect text, number and date/time columns
  • M code generation — create a Power Query script
  • CSV structure analysis — read headers and detect delimiters
  • Variable settings — customize variable names in the code
  • Data preview — preview rows with inferred types
  • Code export — copy the generated M snippet

Use cases:

Prepare CSV imports for Power BI reports and Excel, draft ETL steps and prototype data models.

Supports UTF-8 encoded CSV files
M variable name (letters, digits and underscores only)

Generated M code:


    

Reference

Automatic type inference

  • Int64.Type — integers (-123, 456)
  • type number — decimal numbers (12.34, -5.67)
  • type datetime — date and time (2024-01-15 14:30:00, 2024-01-15T14:30:00)
  • type date — dates (2024-01-15, 2023-12-31)
  • type time — times (14:30, 09:15:30)
  • type logical — Boolean values (TRUE, FALSE)
  • type text — text values (default)

Generated code structure

  • Load the CSV file using Csv.Document
  • Promote headers using Table.PromoteHeaders
  • Convert column types using Table.TransformColumnTypes
  • Set UTF-8 encoding
  • Escape file paths

Using the code in Power BI / Excel

  1. Copy the generated M code
  2. Open Power Query Editor
  3. Create a blank query
  4. Open Advanced Editor
  5. Paste the code and update the file path
  6. Apply the changes
CSV examples
Example 1: Sales
Date,Product,Quantity,Price,IsActive
2024-01-15,Laptop,5,999.99,TRUE
2024-01-16,Mouse,10,25.50,TRUE
2024-01-17,Keyboard,3,75.00,FALSE
Example 2: Date and time data
ID,StartTime,EndTime,Duration,Status
1,09:30:00,17:30:00,8.0,Active
2,10:15:00,16:45:00,6.5,Completed
3,08:00:00,12:00:00,4.0,Pending

More tools

Free tools for analysts and developers