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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Aidan_Wang
New Member

Combine CSV files in folder with different column counts

I am using power query to import multiple CSV files from SharePoint document. But, my files contain a different count of columns:

Most files:

Column AColumn BColumn CColumn DColumn EColumn F
      
      

But some files:

Column AColumn BColumn CColumn DColumn GColumn HColumn EColumn F
        

 

As PQ uses the first file as a sample file, the transform sample file only contains 6 rows. In the final result, the extra two columns (G&H) do not show up but I can't find codes that delete these two columns. I thought Column G&H should show up with most rows are null.

Why did these two columns disappear and how can I make all columns available in the result?

 

Here is my M code:

 

let
    Source = SharePoint.Contents("SITE ADDRESS",[ApiVersion = 15]),
    Documents = Source{[Name="Documents"]}[Content],
    #"Database" = Documents{[Name="Database"]}[Content],
    #"Transaction Detail" = #"Database"{[Name="Transaction"]}[Content],
    #"Expanded Content" = Table.ExpandTableColumn(#"Transaction", "Content", {"Content", "Name", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Folder Path"}, {"Content.Content", "Content.Name", "Content.Extension", "Content.Date accessed", "Content.Date modified", "Content.Date created", "Content.Attributes", "Content.Folder Path"}),
    #"Filtered Hidden Files1" = Table.SelectRows(#"Expanded Content", each [Attributes]?[Hidden]? <> true),
    #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content.Content])),
    #"Removed Other Columns1" = Table.SelectColumns(#"Invoke Custom Function1", {"Transform File"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File"))),

 

 

I really appreciate any help you can provide.

1 REPLY 1
BA_Pete
Super User
Super User

Hi @Aidan_Wang ,

 

It's the Transform From Sample File query that you will need to edit. The code you've provided is for the output query after the sample transformations have been completed.

You should see a helper query folder in your queries list that contains the query I've mentioned above.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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