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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Combine multiple worksheets when loading a folder

Hello everyone, I have a problem that I can't solve, I have some workbooks that I'll load from folder, each workbook has "sheet 1", "Sheet 2" with same data structure and a tab "List", and I want to combine in one table every  "sheet 1" and "sheet 2" from all of the workbooks, but when I load the folder I'm able to only select one tab for example "sheet 1". I'll apreciate any help
Thanks in advance

1 ACCEPTED SOLUTION
KNP
Super User
Super User

Hi @Anonymous ,

 

I would solve it by adding a step in the 'Transform Sample File' code to deal with the first and second sheets independently.

 

Transform Sample File code:

 

let
    Source = Excel.Workbook(Parameter1, null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    FirstSheet = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    Sheet2_Sheet = Source{[Item="Sheet2",Kind="Sheet"]}[Data],
    SecondSheet = Table.PromoteHeaders(Sheet2_Sheet, [PromoteAllScalars=true]),
    Custom1 = Table.Combine({FirstSheet, SecondSheet})

in
    Custom1

 

 

Note that 'Sheet1_Sheet' references 'Source' and 'Sheet2_Sheet' also references 'Source' (not the previous step). 

Then I just used 'Table.Combine' to join the two results together.

 

Here is the code from the main query:

 

let
    Source = Folder.Files("C:\Temp"),
    #"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
    #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File")))
in
    #"Expanded Table Column1"

 

 

Nothing special going on here. This is the standard pattern you get when combining files.

I may have summarized this a little too much depending on your understanding of M. If you need further explanation please let me know.

 

Regards,

Kim

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

You may follow the steps outlined in this video - https://www.youtube.com/watch?v=yL11ugShdrk.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
KNP
Super User
Super User

Hi @Anonymous ,

 

I would solve it by adding a step in the 'Transform Sample File' code to deal with the first and second sheets independently.

 

Transform Sample File code:

 

let
    Source = Excel.Workbook(Parameter1, null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    FirstSheet = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    Sheet2_Sheet = Source{[Item="Sheet2",Kind="Sheet"]}[Data],
    SecondSheet = Table.PromoteHeaders(Sheet2_Sheet, [PromoteAllScalars=true]),
    Custom1 = Table.Combine({FirstSheet, SecondSheet})

in
    Custom1

 

 

Note that 'Sheet1_Sheet' references 'Source' and 'Sheet2_Sheet' also references 'Source' (not the previous step). 

Then I just used 'Table.Combine' to join the two results together.

 

Here is the code from the main query:

 

let
    Source = Folder.Files("C:\Temp"),
    #"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
    #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File")))
in
    #"Expanded Table Column1"

 

 

Nothing special going on here. This is the standard pattern you get when combining files.

I may have summarized this a little too much depending on your understanding of M. If you need further explanation please let me know.

 

Regards,

Kim

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!
Anonymous
Not applicable

this works perfectly, thank u so much

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.