Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Paulinhobh
New Member

Incorrect number of columns CSV

good afternoon people. I'm trying to load a .CSV file through power query. In this file, the first 3 lines are the header, separated by a comma, and the rest are the records. However, despite having only 3 headers, in the records of lines 4, 6, 8 and 11, I have an extra comma. This should generate another column, but my power query is only considering 3 columns. Even when I change the delimiter to "space", only the 3 columns are considered. Can anyone know what could be happening?

 

IMG-20231005-WA0002.jpg

1 REPLY 1
jgeddes
Super User
Super User

My guess is the number of columns was hardcoded as '3' when the file was imported. 

You can verify this by looking in the code line for the source step or in the 'Advanced Editor' and you should see something like...
Csv.Document(File.Contents("C:\pathToFile\TESTFILE.csv"), [Delimiter=",", Columns= 3])

 

If you have a fixed number of columns expected you can change the '3' to the number you expect. If the number of columns will change over time you can use a code like the following in the 'Advanced Editor'...

let
getMaxColumnSize = List.Max(List.Transform(Csv.Document(File.Contents("C:\pathToFile\TESTFILE.csv"),1, ",", ExtraValues.List)[Column1], each List.Count(_))),
Source = Csv.Document(File.Contents("C:\pathToFile\TESTFILE.csv"),getMaxColumnSize, ",")
in
Source





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.