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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Power Query Combine Excel data files with different tab names

Hello, 

i found information on combining a folder of excel files into a single power query that refreshes as files are loaded and taken out of the folder by creating a funtion in powerquery and applying the function to the folder of files. 

the issue i am having is that i am not sure what syntax to use to make the function use the first sheet (the only sheet) in the file regardless of the workbook name, as the names are often different and manually changing it would deffeat the purpose. 

the data is not in a table and i need to convert  it into a table afterwords. I appologize if this is a simple thing, i know mmy way around excel however i have no experiancne with code. 

 

 

here is the funtion i have now which only works for files with a worksheet named "NFB_01_13_19":

 

(filepath)=>
let
Source = Excel.Workbook(File.Contents(filepath), null, true),
#"NFB 01_13_1" = Source{[Name="NFB 01_13_2019"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"NFB 01_13_1"),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{XXXXXXXXX})
in
#"Changed Type"

1 ACCEPTED SOLUTION
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

Based on my test, you could refer to below code in query editor:

 

(para as text)=>
let
    a = Folder.Files(para){0}
in
    a

Enter your file path as parameter and it will choose the first sheet automatically:

1.PNG

1.PNG

Hope it could help you.

 

Regards,

Daniel He

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered to close this topic?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

Based on my test, you could refer to below code in query editor:

 

(para as text)=>
let
    a = Folder.Files(para){0}
in
    a

Enter your file path as parameter and it will choose the first sheet automatically:

1.PNG

1.PNG

Hope it could help you.

 

Regards,

Daniel He

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

I Tried this (which i picked up from another topic) but it errored out on all the files:

 

(filepath)=>
let
Source = Excel.Workbook(File.Contents(filepath), null, true),
FirstSheet = Table.SelectRows(Source, each [Kind] = "Sheet"){0}[Data],
#"Sheet" = Source{[Name="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"Sheet"),

#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{XXXXXXXXX})
in
#"Changed Type"

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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