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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
wdvro
Frequent Visitor

Merge specific tabs excelfiles SharePoint Folder

Best,

I am facing a specific problem.

Just some context: every Wednesday I receive via e-mail an excel (xlsx) file containing 3 tabs:
- Tab 1: table of contents
- Tab 2: effective dates: hotel occupancy for the next 90 days
- Tab 3: help


Every four weeks, however, a tab is added to that file. Then the file looks like this.
- Tab 1: table of contents
- Tab 2: actual dates: hotel occupancy for the next 90 days
- Tab 3: actual dates: hotel occupancy for the next 365 days
- Tab 4: help

 

The files arrive in my mailbox and are then automatically copied to a SharePoint folder via Power Automate.

 

Additional difficulty: the data provider occasionally changes the names of the tabs.

 

Anyone here to help me get the data related to hotel occupancy for the next 365 days (i.e. tab 3 in the file forwarded every 4 weeks) into the data model? How can I write this in Power Query?


Thanks in advance! 

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

If you want to select the third tab from every file that has four tabs you could do something like...

jgeddes_0-1708459479578.png

add a column that gives the excel content for each file

 

= Table.AddColumn(PREVIOUSSTEP, "_excelContent", each Excel.Workbook([Content]))

 

clicking in either row in the '_excelContent' column will show the listing of sheets, tables etc for that file...

jgeddes_1-1708459599861.png

We are only concerned with 'Sheets' so I used a nested function to filter the nested tables to include only 'Sheets'...

 

fxSelectRows = 
    (inputTable as table) as table =>
    let
        source = inputTable,
        selectSheets = Table.SelectRows(inputTable, each [Kind] = "Sheet")
    in
        selectSheets

 

 

 

= Table.TransformColumns(PREVIOUSSTEP, {{"_excelContent", each fxSelectRows(_)}})

 

 

you now have only 'Sheets'

jgeddes_2-1708459770691.png

Now we only want rows in our table to include files with four tabs...

 

= Table.SelectRows(PREVIOUSSTEP, each List.Count(Table.ToRows([_excelContent])) = 4)

 

 

jgeddes_4-1708459871197.png

now we only want the third tab...

 

= Table.TransformColumns(PREVIOUSSTEP, {{"_excelContent", each Table.Range(_, 2, 1)}})

 

and you end up with...

jgeddes_5-1708459943153.png

from here you can combine the files into a single table and you are all set.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

1 REPLY 1
jgeddes
Super User
Super User

If you want to select the third tab from every file that has four tabs you could do something like...

jgeddes_0-1708459479578.png

add a column that gives the excel content for each file

 

= Table.AddColumn(PREVIOUSSTEP, "_excelContent", each Excel.Workbook([Content]))

 

clicking in either row in the '_excelContent' column will show the listing of sheets, tables etc for that file...

jgeddes_1-1708459599861.png

We are only concerned with 'Sheets' so I used a nested function to filter the nested tables to include only 'Sheets'...

 

fxSelectRows = 
    (inputTable as table) as table =>
    let
        source = inputTable,
        selectSheets = Table.SelectRows(inputTable, each [Kind] = "Sheet")
    in
        selectSheets

 

 

 

= Table.TransformColumns(PREVIOUSSTEP, {{"_excelContent", each fxSelectRows(_)}})

 

 

you now have only 'Sheets'

jgeddes_2-1708459770691.png

Now we only want rows in our table to include files with four tabs...

 

= Table.SelectRows(PREVIOUSSTEP, each List.Count(Table.ToRows([_excelContent])) = 4)

 

 

jgeddes_4-1708459871197.png

now we only want the third tab...

 

= Table.TransformColumns(PREVIOUSSTEP, {{"_excelContent", each Table.Range(_, 2, 1)}})

 

and you end up with...

jgeddes_5-1708459943153.png

from here you can combine the files into a single table and you are all set.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.

Top Solution Authors