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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors