Using power query to combine multiple files that have a different amount of columns

ESACAWIP

New Member
Joined
Nov 9, 2020
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Example:

Does anyone know how to combine multiple files that contain a different amount of columns with power querry?
-Column names that are the same and should all line up
-Some spreadsheets have additional columns (e.g. File 3, Column "Education 2"), which the other spreadsheets do not have
-I can not manually add or rearrange columns in the spreadsheets as I have hundreds of files, with each file containing hundreds of columns
-For the final output / result, I do not need the columns in any specific order. I just need to preserve all the data


Can someone point me in the right direction? When I tried to combine the worksheets, I ended up missing columns for some reason.



NameAgeWork History 1Education 1
File 1John
17​
Toys R usJeffersion High School
NameAgeWork History 1Work History 2Education 1
File 2Paul
19​
OfficeMaxMcDonaldsAdams High School
NameAgeWork History 1Education 1Education 2
File 3Steven
31​
CostcoDouglass High SchoolStevens School

Output:

NameAgeWork History 1Education 1Work History 2Education 2
File 1John
17​
Toys R usJeffersion High SchoolNullNull
File 2Paul
19​
OfficeMaxAdams High SchoolMcDonaldsNull
File 3Steven
31​
CostcoDouglass High SchoolNullStevens School
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Load each table to the PQ Editor. Close and Load each to a connection. Then combine them in a new append query.



Power Query:
let
    Source = Table.Combine({Table1, Table2, Table3})
in
    Source

Book2
ABCDEFG
4Column1NameAgeWork History 1Education 1Work History 2Education 2
5File 1John17Toys R usJeffersion High School
6File 2Paul19OfficeMaxAdams High SchoolMcDonalds
7File 3Steven31CostcoDouglass High SchoolStevens School
Sheet1
 
Upvote 0
I have hundreds of files, with each file containing hundreds of columns
Based on this comment, I don't think @alansidman's suggestion is going to be viable.
I suggest you have a look at Wyn Hopkins 9 min video here.
Maybe set up the code with only a few files in the folder before running it against all your files.

 
Upvote 0
Based on this comment, I don't think @alansidman's suggestion is going to be viable.
I suggest you have a look at Wyn Hopkins 9 min video here.
Maybe set up the code with only a few files in the folder before running it against all your files.


It seems like this video is exactly what im looking for but when I followed the steps exactly, it always crashes my excel (even when combining just 2 files)

Each file has around 2000 columns though so maybe thats why 😭
 
Upvote 0
The file type is csv. In the video, it walks me through how I can grab all the headings (column headers) from all files rather than 1 example file. After that, I used the list.union function to keep only unique headers instead of duplicates. (=Table.ExpandTableColumn (ReadyToExpand, "Transform File", HEADINGS))

^When I expand using this list, that is when the preview screen gets stuck in this infinite loading cycle. I hit load into table anyway and at around 20 minutes, it will crash my computer.

I am using office 360 / 64 bit on a fairly new computer.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top