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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors