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
fab
Helper I
Helper I

Load only Excel tabs based on certain value

Hello,

I have an Excel file with many tabs.
I would like to load (Power BI desktop) automatically tabs that contain a certain value in theirs names.

How can I do that ?


Thank for your help.

1 ACCEPTED SOLUTION

Ok,

So try this: Open the Query Editor, copy/paste the following M code (advanced editor) and adapt the green part.

 

let
    Source = Excel.Workbook(File.Contents("YourExcelFileFullPath"), true, true),
    KeepCol = Table.SelectColumns(Source,{"Name", "Data"}),
    Test = Table.AddColumn(KeepCol, "Flag", each Text.Contains([Name],"YourTestWord")),
    KeepTrue = Table.SelectRows(Test, each ([Flag] = true)),
    Expand = Table.ExpandTableColumn(KeepTrue, "Data", {"Column1", "Column2", "Column3", "Column4", "Column5"}, {"Column1", "Column2", "Column3", "Column4", "Column5"})
in
    Expand

View solution in original post

5 REPLIES 5
Datatouille
Solution Sage
Solution Sage

Hi,

 

The tabs which match your name's condition(s), do they all have the exact same format ?

Yes,

 

For instance, I have the excel file with these tabs :

- 1_internal

- 1_customer

- 2_internal

- 2_customer

-....

 

Tabs withs "internal" have the same format (but not the others...) and I want to load only these one.

Ok,

So try this: Open the Query Editor, copy/paste the following M code (advanced editor) and adapt the green part.

 

let
    Source = Excel.Workbook(File.Contents("YourExcelFileFullPath"), true, true),
    KeepCol = Table.SelectColumns(Source,{"Name", "Data"}),
    Test = Table.AddColumn(KeepCol, "Flag", each Text.Contains([Name],"YourTestWord")),
    KeepTrue = Table.SelectRows(Test, each ([Flag] = true)),
    Expand = Table.ExpandTableColumn(KeepTrue, "Data", {"Column1", "Column2", "Column3", "Column4", "Column5"}, {"Column1", "Column2", "Column3", "Column4", "Column5"})
in
    Expand

I would like to complete this query:

Your solution is working fine for one file.

 

How can I to apply this code for all files (xls same structure) in a folder ?

(I want names of tabs and files as a column too).

Ok this one should work:

 

 

let
    Source = Folder.Files("YourFolderPath"),
    KeepCol = Table.SelectColumns(Source,{"Name"}),
    Sheet_Info = Table.AddColumn(KeepCol, "Personnalisé", each Excel.Workbook(File.Contents("YourFolderPath" & [Name])),
    ExpandSheet = Table.ExpandTableColumn(Sheet_Info, "Personnalisé", {"Name", "Data"}, {"Name.1", "Data"}),
    Test = Table.AddColumn(ExpandSheet, "Flag", each Text.Contains([Name.1],"YourTestWord")),
    KeepTrue = Table.SelectRows(Test, each ([Flag] = true)),
    Develop = Table.ExpandTableColumn(KeepTrue, "Data", {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6"}, {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6"})
in
    Develop

 

 

Helpful resources

Announcements
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.